151. Reverse Words in a String
没什么说的
1 public String reverseWords(String s) { 2 if(s == null || s.length() == 0) { 3 return ""; 4 } 5 s = s.replaceAll(" +", " "); 6 System.out.println(s); 7 List<String> words = new ArrayList<String>(Arrays.asList(s.split(" "))); 8 words.remove(""); 9 Collections.reverse(words); 10 return String.join(" ", words); 11 }