使用StringBuffer或者StringBuilder中的reverse()方法。
public static void main(String[] args) {
StringBuffer stringBuffers = new StringBuffer("abcdefg");
();
(stringBuffers);
StringBuilder stringBuilder = new StringBuilder("hijklmn");
();
(stringBuilder);
}
代码输出
gfedcba
nmlkjih