public static void main(String[] args) {
new FindWords().findWords("zero hello 你好world");
}
public void findWords(String input) {
char[] source = input.toCharArray();
int k = 0,
wlen = source.length;
// contains A-Z and whilespace
StringBuffer word = new StringBuffer();
while(k < wlen) {
char w = source[k];
if(Pattern.matches("[A-Za-z]|\\s", String.valueOf(w))) {
word.append(w);
}
k++;
}
//result : zero hello world
System.out.println(word);
//asList
//result : [zero, hello, world]
List<String> words = Arrays.asList(word.toString().split("\\s"));
System.out.println(words);
//sort
Collections.sort(words, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
//result : [hello, world, zero]
System.out.println(words);
}