Today I discovered that StringTokenizer is considered a legacy class by Sun. It’s retained for compatibility reasons although its use is discouraged in new code. Sun recommends the use of the split method in the String class or using the java.util.regex package instead.
By using the split method you lose the option to include the seperator-character in the split set. For parsing EDI I wanted to split an EDI segment on seperator characters + or : but I want to make sure that the seperator characters are included in the split set, so I can check if the right seperator-character was used in the original file. With StringTokenizer this can easily be done by calling java.util.StringTokenizer tokenizer=new java.util.StringTokenizer (segment,”+:”,true);