【Java】String字符串反转

 

    @Test
    public void testStringReverse(){
        String str = "abcdABCD";
        StringBuilder stringBuilder = new StringBuilder(str);
        System.out.println(String.format("反转前:%s", str)); // abcdABCD
        System.out.println(String.format("反转后:%s", stringBuilder.reverse())); // DCBAdcba
    }

 

posted @ 2022-07-14 11:05  淡怀  阅读(167)  评论(0编辑  收藏  举报