How is the String passed to this method getting reversed? If you pass "ABCD" the string become "DCBA", but I was thinking reverse(str.substring(1)) will call it self until it return "D" which will be concatenated with str.substring(0,1) which is D and the string returned to be "DD".JAVA programming Language.
private static String reverse(String str) {
if (str.length() <= 1) {
return str;
}
return reverse(str.substring(1)) + str.substring(0, 1);
}