Java中如何将字符串进行反转

时间:2025-04-04 13:21:37

使用StringBuffer或者StringBuilder中的reverse()方法。

    public static void main(String[] args) {
        StringBuffer stringBuffers = new StringBuffer("abcdefg");
        ();
        (stringBuffers);
        StringBuilder stringBuilder = new StringBuilder("hijklmn");
        ();
        (stringBuilder);
    }

代码输出

gfedcba
nmlkjih