Learned this new was to split a string
public String[] split(String regex)

Apparently this got introduced in 1.4 . In many cases, I can now replace the StringTokenizer with this.

StrikTokenizer is still faster. If it can do the job, use it. For more complex splitting, use the regex engine as you found out.
# posted by Anonymous : 7/14/2004 05:51:51 AM

You are right.
There is a huge performance difference.
# posted by Lokesh : 7/14/2004 07:00:18 AM

I’ve not benchmarked this, but if performance becomes an issue, then precompiling the regex should improve things:

private static final Pattern splitPattern = Pattern.compile(“:”);


Tom Hawtin
# posted by Anonymous : 7/14/2004 11:55:20 AM

Thanks Tom.
Precompiling certainly improves performance, but for simple splits, StringTokenizer performs much better.
# posted by Lokesh : 7/14/2004 05:23:32 PM