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     }

 

posted @ 2016-06-21 09:28  warmland  阅读(98)  评论(0编辑  收藏  举报