Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Diff bet string.split and StringTokenizer 1

Status
Not open for further replies.

gadabout

Programmer
Jan 15, 2003
6
IN
What is difference between string.split function and StringTokenizer class?
 
String.split returns an array so you got to use the return value by indexing the differents "cells" to get them.
StringTokenizer is a class that permits a different acces to the values. In fact, it depends on what you want to do with slited data. If you want to acces it sequentially, use StringTokenizer and its "hasmoretokens" and "nextToken" methods. If you want to access it randomly, use split because you can, this way access directly the "cell" you want.
Another difference is in the delimiter used to split. With String.split, you can use regExp to cut your string, with StringTokenizer, you can provide one or more chars as delimiters.

Hope that helps. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top