Easy way to reverse String

后端 未结 12 1039
野性不改
野性不改 2021-02-13 04:01

Without going through the char sequence is there any way to reverse String in Java

12条回答
  •  青春惊慌失措
    2021-02-13 04:35

    This is a way to do so using recursion -

    public static String reverse(String s1){
            int l = s1.length();
            if (l>1)
                    return(s1.substring(l-1) + reverse(s1.substring(0,l-1)));
            else
                    return(s1.substring(0));
    }
    

提交回复
热议问题