File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 9382
    
    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: 9382
    
    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
 
Don't get me started about those stupid light bulbs.
 
subject: StringTokenizer Question?