Hello, Chris Smith !
You said:
Basically, it deals with code like:
StringTokenizer st = new StringTokenizer("test:1,2", ":");
System.out.println(st.nextToken());
System.out.println(st.nextToken(","));
IIRC, in versions prior to 1.3, the colon delimiter is consumed by the
first nextToken operation. In versions 1.3 and above, it is not, and
the second token returned is ":1".
Okay, that was more than 10 words.
I got bit by that one by myself, which led me to file bug
4645089, which basically said that since they changed the
behavior they have essentially made the method worthless because
you can't know what behavior the VM will have. I said they might
as well deprecate the method.
They didn't deprecate it officially, but beginning in 1.4 the
javadocs say that StringTokenizer is only there for supporting
legacy code and is not recommended for new code.
And considering the new behavior, I don't think there is anyway
to actually use it in a beneficial way. I can't think of any real
world application where you would actually want the delimiter(s)
returned and there really isn't a clean, simple workaround to
remove the delimiters at the beginning in general.
To show what I mean about the difficulty in stripping it consider
this case:
StringTokenizer st = new StringTokenizer(s, ": ");
t1 = st.nextToken();
t2 = st.nextToken(" ,"));
t3 = st.nextToken();
I changed Chris' examle by having sace also a delimiter. If I run
this on "test : 1, :w" it works as expected before 1.3, but in
1.3 you get "the colon as the second token.
And if the string didn't have the spaces you have the additional
complication that you should only strip the colon from the first
entry in the comma separated list which complicates any loop to
read them.
While you can come up with solutions they are generally more
complex than just doing the whole scanning job yourself without
the "aid" of StringTokenizer.
All this is on top ofall of its failings with respect to handling
CSV files.
So my general advice is the same as Sun's, avoid the class
altogether . Use the String.split method which is much more
powerful or there are better replacements which work better out
there.
So I would question whether there is any benefit to a tutorial
for newbies when we should be telling them to not use the class.