Notice
Recent Posts
Recent Comments
Link
관리 메뉴

설.현.아빠

StringTokenizer API 본문

안드로이드/String

StringTokenizer API

설.현.아빠 2011. 2. 11. 11:40



StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.

A token is returned by taking a substring of the string that was used to create the StringTokenizer object.

The following is one example of the use of the tokenizer. The code:

StringTokenizer st = new StringTokenizer("this is a test");

while (st.hasMoreTokens()) {

System.out.println(st.nextToken());

}

prints the following output:

this

is

a

test

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

The following example illustrates how the String.split method can be used to break up a string into its basic tokens:

String[] result = "this is a test".split(\\s);

for (int x=0; x<result.length; x++)

System.out.println(result[x]);

 

prints the following output:

this

is

a

test

Comments