标签:split equal ever -- reverse str public html 用法
示例:
输入:
"the sky is blue",
输出:
"blue is sky the".
public String reverseWords(String s) {
StringBuilder sb = new StringBuilder();
if(s == null || "".equals(s.trim())){
return "";
}else{
String [] strs = s.trim().split("\\s+");
int len = strs.length-1;
for(int i=len;i>=0;i--){
if(i == 0){
sb.append(strs[i]);
}else{
sb.append(strs[i]+" ");
}
}
return sb.toString();
}
}
trim()去除字符串两头空格,split()的用法
标签:split equal ever -- reverse str public html 用法
原文地址:https://www.cnblogs.com/lihanqing/p/12333534.html