String and StringTokenizer
What is difference between String and StringTokenizer?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Apr 16, 2014, 9:11 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 17, 2014, 1:21 AM EDT
Note that this question relates to Java, not C# (and Lakshmanan has answered accordingly) because .NET doesn't have a StringTokenizer class.
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 17, 2014, 3:48 AM EDT
You can think of the StringTokenizer as a specialized form of StreamTokenizer, where each token that is returned is a String. Depending upon what you want to do with the resultant tokens and/or how complex of a parse job you want to deal with lets you decide which to use.
The StringTokenizer parses a string into a series of tokens. It is then your responsibility to figure out what each token returned is, beyond the definition of a token separated by delimiters. Usually, you just treat things as words when using StringTokenizer.
On the other hand, a StreamTokenizer allows you to ask is the next token a number, word, quoted string, end-of-file, end-of-line, comment, or whitespace. In this case, the StreamTokenizer is smarter, though can be considerably harder to use.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Apr 17, 2014, 5:21 AM EDT