java字符串反转

时间:2022-07-17 11:07:55
public class StringReverse(){
public static void main(){
String str="ReverseMe";
/**
*将String 对象转换为可改变的StringBuffer类对象
*然后调用StringBuffer类的reverse()方法实现反转
**/

String reverseResult = newStringBuffer(str).
System.out.println("\nString before reverse:
"
+str);
System.out.println("String after reverse:
"
+reverseResult);
}
}