This may not answer your question exactly, but, quoting StringTokenizer docs,
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.
Unfortunately, this doesn't mention exactly why it's discouraged. And the reason is, you have to load the entire string into memory anyway to use StringTokenizer
, and that implies you're not terribly memory-constrained, so why not use split
? Pretty much the only reason to use StringTokenizer
today is when you set returnDelims
to true
(if different delimiters mean different things to you) because you can't do that with split
.
If you still have some reason to use StringTokenizer
, then you have a serious problem here. StringTokenizer
is not Serializable
, and you can't inherit from it and make it Serializable
because it doesn't have the void constructor. Which means your only way is to use reflection, possibly with some 3rd party serialization libraries, maybe serialize it to XML/JSON. But the absence of default constructor may limit your choices here as well. When deserializing, you'll have to construct the tokenizer with some dummy string first, and then set its fields via reflection.