Java 实例 - 字符串反转


以下实例演示了如何使用 Java 的反转函数 reverse() 将字符串反转:

public class StringReverseExample{
   public static void main(String[] args){
      String string="abcdef";
      String reverse = new StringBuffer(string).
      reverse().toString();
      System.out.println("\nString before reverse:
      "+string);
      System.out.println("String after reverse:
      "+reverse);
   }
}

以上代码实例输出结果为:

String before reverse:abcdef
String after reverse:fedcba