StringTokenizer vs. String.split

which is better stringtokenizer or string.split? which of the two can parse faster?
[90 byte] By [kneelmara] at [2007-11-26 23:56:31]
# 1
I can't remember where I have seen the comparison of these two methods.It mentioned that split performs faster.Beside performance issue, you should also consider the requirements.And split does not support in old version.
rym82a at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 2
StringTokenizer is handy and have many supportive methods for handling.Split returns the String Array.
jawadhashmia at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 3
StringTokenizer can split strings based on single characters, split() takes regular expressions. I imagine that might make split() a bit slower when splitting for single characters (can't be arsed to test it though), but usually it's more handy.
-Kayaman-a at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 4

> which of the two can parse faster?

General rule of programming....

A class written for a specific purpose will generally be faster than a class written for general purpose.

Of course you also have to define "parse", because each works differently, so you need to pick the one that does what you want.

camickra at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 5
tokenizer will be much more efficient.. imo
Alandera at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 6

If both approaches are equally appropriate, and if their relative performance is really an issue, StringTokenizer can be faster than split() can. But choosing between the two purely on the basis of performance is asinine. A better question would be, if you could only have one of them in your toolbox, which would you choose? StringTokenizer is like one of those new [url=http://herrington-catalog.stores.yahoo.net/t266.html]bionic wrenches[/url]: it's quick and convenient, assuming you can fit it into the space where you need to use it. But split() is more like a full set of socket wrenches: it requires a little more up-front effort on your part, but it's much more flexible and powerful.

uncle_alicea at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 7

> StringTokenizer is like one of those new

> [url=http://herrington-catalog.stores.yahoo.net/t266.h

> tml]bionic wrenches[/url]: it's quick and convenient,

> assuming you can fit it into the space where you need

> to use it. But split() is more like a full set of

> socket wrenches: it requires a little more up-front

> effort on your part, but it's much more flexible and

> powerful.

I think you have those 2 reversed?

TuringPesta at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 8

> I think you have those 2 reversed?

You mean, because the bionic wrench is the newer technology? My point is that, if you can use it, it will be quicker, but there will inevitably be situations where it won't work at all. Just like when you want to split a string on a multi-character delimiter: StringTokenizer can't do it. But split() can do everything StringTokenizer can, and much more.

uncle_alicea at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 9
> StringTokenizer is handy and have many supportive> methods for handling.> Split returns the String Array.Huh?
bckrispia at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...
# 10
> ... > one of those new bionic wrenches: it's quick and convenient,> ...That's a handy tool!...But is it faster than a StringTokenizer?
prometheuzza at 2007-7-11 15:41:55 > top of Java-index,Java Essentials,Java Programming...