This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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]);
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.