• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringTokenizer Question?

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Why is the StringTokenizer class in java 1.5 deprecated?? Any obvious reasons. Any better alternative to it?
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following quote can be read in the Javadoc:

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

The following example illustrates how the String.split method can be used to break up a string into its basic tokens:

String[] result = "this is a test".split("\\s");
for (int x=0; x<result.length; x++)
System.out.println(result[x]);
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringTokenizer is not actually deprecated - if it were, then it would be labeled as deprecated in the API, and you would get compiler warnings when using it. Its use is discouraged in newer code, but that's not as strong a statement as saying it's deprecated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic