String Tokenizer

This post was moved to http://srinichekuri.com/2008/09/23/stringtokenizer/

**********************************************************************

String tokenizer has been made better in 1.5 when compared to the same in 1.2 version.

String tokenizer in 1.2:

String str = “Hello World”;
StringTokenizer st = new StringTokenizer();
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

String tokenizer in 1.5:

String str = “Hello World”;
String[] result = str.split(” “);
for (int x=0; x<result.length; x++)
System.out.println(result[x]);

The redundecy of using tokens has been eliminated in 1.5 inturn making our life easier.

Advertisements