This piece of code reverses string parameter passed to it. I know that string is immutable. I seem not to understand what is going on. Where does it store the reversed string that it returns.
public static String reverseRecursively(String str) {
//base case to handle one char string and empty string
if (str.length() < 2) {
return str;
}
return reverseRecursively(str.substring(1)) + str.charAt(0);
}