使用java.util包下的StringTokenizer类可以你说的问题。。 StringTokenizer st = new StringTokenizer("this is a test"); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } 输出以下字符串: this is a test也可以使用String类的split()方法 String[] result = "this is a test".split("\\s"); for (int x=0; x<result.length; x++) System.out.println(result[x]); 输出以下字符串: this is a test
Str="This is a"; String[] s = Str.split("") ; int i = s.length() 就有i个单词啊
Str.length();返回一个整数9
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
输出以下字符串:
this
is
a
test也可以使用String类的split()方法
String[] result = "this is a test".split("\\s");
for (int x=0; x<result.length; x++)
System.out.println(result[x]); 输出以下字符串:
this
is
a
test
String[] s = Str.split("") ;
int i = s.length()
就有i个单词啊