Given an input string, reverse the string word by word.
For example,
Given s = " the sky is blue ",
Return " blue is sky the ".
1 Public classSolution {2 Publicstring Reversewords (string s) {3 if(S.equals (""))returns;4String Arr[]=s.split ("");5String new_word= "";6 for(inti=arr.length-1;i>=0;i--)7 {8 if(Arr[i].equals (""))Continue;9New_word+=arr[i]+ "";Ten } Onenew_word=new_word.tostring (). Trim (); A returnNew_word; - } -}
After finishing reading the answers to others found useful StringBuilder
So I went to study the three difference in 100000 complexity stringbulder and buffer are not a bit faster than string.
So:
1. If you want to manipulate a small amount of data with = String
2. Manipulating large amounts of data under a single-threaded operation string buffer = StringBuilder
3. Multi-threaded operation string buffer operation large amount of data = StringBuffer