用递归实现字符串反转

简单又常见

被这简洁的写法惊艳到了!

public static String reverse(String originStr) {
        if(originStr == null || originStr.length() <= 1) 
            return originStr;
        return reverse(originStr.substring(1)) + originStr.charAt(0);
    }

你可能感兴趣的:(java)