当前位置: 技术问答>java相关
哪位大虾能给一个StringTokenizer的例子?
来源: 互联网 发布时间:2015-01-02
本文导语: 有关java.util.StringTokenizer的一个能用的例子。谢谢! | 要是我想把空格换成字符A,只要初始化参数变化就可以了。 import java.util.*; class stk { public static void main(String[] args) { System.out.printl...
有关java.util.StringTokenizer的一个能用的例子。谢谢!
|
要是我想把空格换成字符A,只要初始化参数变化就可以了。
import java.util.*;
class stk
{
public static void main(String[] args)
{
System.out.println("Hello World!");
StringTokenizer st = new StringTokenizer("this is a test","a");
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
}
请看这段javadoc :
StringTokenizer
public StringTokenizer(String str,
String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Parameters:
str - a string to be parsed.
delim - the delimiters.
import java.util.*;
class stk
{
public static void main(String[] args)
{
System.out.println("Hello World!");
StringTokenizer st = new StringTokenizer("this is a test","a");
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
}
请看这段javadoc :
StringTokenizer
public StringTokenizer(String str,
String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Parameters:
str - a string to be parsed.
delim - the delimiters.