Java split()方法
例子:
查找 "In spite of everything, I still believe that people are really good at heart."中有多少个英文单词。
使用split()方法:
public class javasplit {
public static void main(String[] args) {
int count = 0;
String str ="In spite of everything, I still believe that people are really good at heart.";
for (String str2:str.split(" ")){
count++;
}
System.out.println(count);
}
}
结果: