Ok simple short and sweet. I'm writting an application that used the StringTokenizer to parse thru data. I am delimiting it by comma (,).
Example Data: "a,b,c,,e" When I iterate thru the String I would expect the StringTokenizer to process this result: "a" "b" "c" "" "e" Instead I'm getting: "a" "b" "c" "e"
Any idea why the StringTokenizer isn't tokenizing empty Strings??? I looked in the javadoc and it says nothing about ignoring empty Strings. I guess I could write my own tokenizer or do something to the data before tokenizing to place N/A where data doesn't exist. But don't want to go to the trouble if it's handled somehow in the StringTokenizer class.
SCJP 1.4, SCWCD
Java: The power, elegance, and simplicity of a hand grenade
By default, StringTokenizer groups one or more consecutive delimiter characters together to separate tokens. However, it has an alternate method that will return both the tokens and each single delimeter character, also as a token.
If the returnDelims flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens.
While not as simple to use as String.split(","), it would allow you to determine when to create empty tokens. If you have to run in pre-1.4 JVMs, it's a reasonable route. Of course, if comma is your only delimiter character, you could write your own split method in a few lines of code. [ April 30, 2005: Message edited by: David Harkness ]
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad: