Reverse the string

 

public class Demo {
    public static void main(String[] args) {
        String str = "ABCDEFG";
        StringBuffer sb = new StringBuffer(str);
        StringBuffer reverse = sb.reverse();
        System.out.println(reverse);
        String reverse2 = reverse(str);
        System.out.println(reverse2);
    }
    public static String reverse(String str) {
        if(str == null || str.length() <= 1)
            return str;
            return reverse(str.substring(1)) + str.charAt(0);
    }
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325688191&siteId=291194637