java字符串反转

1、递归反转

1 public static String reverseString(String x) {
2         if (x == null || x.length() < 2)
3             return x;
4         else
5             return reverseString(x.substring(1)) + x.charAt(0);
6}

2、jdk自带的方法

1 public static String reverse(String str){
2      return new StringBuilder(str).reverse().toString();
3}

3、使用charAt()方法

1 public static String reverse(String str){  
2         String c ="";
3         for (int i = str.length() - 1; i >= 0; i--) {  
4               
5             c+= str.charAt(i);  
6               
7         }  
8         return c;
9 }    
原文地址:https://www.cnblogs.com/kingxiaozi/p/3986369.html