Why is StringTokenizer deprecated?
- Java 10 String Tokenizer -- not deprecated
- Java 9 String Tokenizer -- not deprecated
- Java 8 String Tokenizer -- not deprecated
- Java 7 String Tokenizer -- not deprecated
- Java 6 String Tokenizer -- not deprecated
- Java 5 String Tokenizer -- not deprecated
If it is not marked as deprecated, it is not going away.
From the javadoc for StringTokenizer:
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.
If you look at String.split()
and compare it to StringTokenizer
, the relevant difference is that String.split()
uses a regular expression, whereas StringTokenizer
just uses verbatim split characters. So if I wanted to tokenize a string with more complex logic than single characters (e.g. split on \r\n
), I can't use StringTokenizer
but I can use String.split()
.
StringTokenizer is not deprecated in fact StringTokenizer is 4X faster than String.split() and in competitive programming it is used by many developers.
Source :- Faster Input for Java