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(); } }