Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
public class Solution {
public String reverseWords(String s) {
String afterTrim= s.trim();
String[] split=afterTrim.split(" +"); //注意res
StringBuilder sb= new StringBuilder();
for(int i=split.length-1;i>=0;i--){
sb.append(split[i]+" ");
}
return sb.toString().trim();
}
}
(String)151. Reverse Words in a String
原文:http://www.cnblogs.com/kydnn/p/5373269.html