/**
* 递归小技巧
*
* @param args
*/
public static void main(String[] args) {
String str = "abcdefg";
System.out.println(reverse0(str));
}
/**
* 语法啰嗦-逻辑清晰
*
* @param str
* @return
*/
private static String reverse(String str) {
if (str.isEmpty()) {
return str;
} else {
return reverse(str.substring(1)) + str.charAt(0);
}
}
/**
* 语法简洁-略显抽象
*
* @param str
* @return
*/
private static String reverse0(String str) {
return str.isEmpty() ? str : reverse(str.substring(1)) + str.charAt(0);
}