几种常用的java 实现反转的方法———reverse

1.最简单的方法

public static String reverse1(String str)

   return new StringBuffer(str).reverse().toString();

2.最常用的方法:

 { 

   char[] array = s.toCharArray(); 

 String reverse = " "; <wbr=""> //注意这是空串,不是null

   for (int i = array.length - 1; i >= 0; i--) 

   reverse += array[i]; 

   return reverse; 

  } 

 public static String reverse2(String s)

  int length = s.length(); 

  String reverse = " "; <wbr=""> //注意这是空串,不是null

   for (int i = 0; i < length; i++) 

    reverse = s.charAt(i) + reverse;//在字符串前面连接,而非常见的后面

   return reverse;

 }

原文地址:https://www.cnblogs.com/lyugeyi1030/p/8542375.html