如何将字符串反转?
发布于 2020-01-08 09:14:21
关注者
0
被浏览
1107
1 个回答
-
使用 StringBuilder 或者 stringBuffer 的 reverse() 方法。 示例代码:
// StringBuffer reverse StringBuffer stringBuffer = new StringBuffer(); stringBuffer. append("abcdefg"); System. out. println(stringBuffer. reverse()); // gfedcba // StringBuilder reverse StringBuilder stringBuilder = new StringBuilder(); stringBuilder. append("abcdefg"); System. out. println(stringBuilder. reverse()); // gfedcba