1. 程式人生 > >字串倒序單詞順序不變保留空格

字串倒序單詞順序不變保留空格

     // hello world xiao hong >>> hong xiao world   hello
     public static String conversionStr(String string)
     {
         if (string == null || "".equals(string))
             return null;
         String[] arrStr = string.split(" ");
         StringBuilder sb = new StringBuilder(string
.length()); for (int i=arrStr.length-1;i>=0;i--) { sb.append(arrStr[i]).append(" "); } return sb.toString(); }