public static List<String> getWords(String p){
List<String> list = new ArrayList<>();
int index = 0;
String word = "";
while(index < p.length()){
char c = p.charAt(index);
if((c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A') || c == '\''){
word+=c;
index++;
}else{
if(!word.equals("")) {
list.add(word);
word = "";
}
index++;
}
}
if(!word.equals(""))list.add(word);
return list;
}
其中,参数名p表示整篇英文文章。
调用此方法可以得到所有的英文单词,英文单词还包括特殊的单词,例如:I'm,boys'等。