/*
* 翻转字符串
*/
public static void reverseStr(){
String str = "123";
// stringBuffer.reverse() 翻转字符串
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(str);
stringBuffer.append("str");
stringBuffer.reverse();
// stringBuilder.reverse() 翻转字符串
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(str);
stringBuilder.append("str");
stringBuilder.reverse();
System.out.println("StringBuffer的翻转字符串:【" + stringBuffer + "】, StringBuilder的翻转字符串:【" + stringBuilder + "】");
}
【翻转字符串】
于 2022-06-21 09:51:38 首次发布