递归实现字符串的反转

public class StringFanZhuan {

    public static String reverse1(String originStr) {

       if(originStr == null || originStr.length() <= 1)
            return originStr;
        return reverse1(originStr.substring(1) )+ originStr.charAt(0);
    }


    public static void main(String[] args){
        String a1="dasofisjkashaiuoajaafo";
        String a2 = reverse1(a1);
        System.out.println("reverse1方法反转" + a2);
    }

}

你可能感兴趣的:(递归实现字符串的反转)