my dog learned polymorphism*
The moose likes Beginning Java and the fly likes StringTokenizer Question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringTokenizer Question?" Watch "StringTokenizer Question?" New topic
Author

StringTokenizer Question?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Why is the StringTokenizer class in java 1.5 deprecated?? Any obvious reasons. Any better alternative to it?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
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

Joined: Sep 26, 2006
Posts: 9345
    
    2

Thanks for the help.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringTokenizer Question?
 
Similar Threads
Alternative to StringTokenizer
Alternative to StringTokenizer
Please help.... Read data in between
Alternative to StringTokenizer
GWT with arrayDeque and StringTokenizer Problem