When you call the function, it takes the 1st character ‘ str.charAt(0)’ of the string and places it at the end. Then it calls the itself - reverse() - on the remainder - str.substring(1). When you add it together, you get the result reverse(str.substring(1)) + str.charAt(0)
When the passed String has one character or less with no remainder left (str.length() <= 1), then it stops calling itself recursively to return the passed string.
See the below implementation to understand how it works:
reverse("Hello")
(reverse("ello")) + "H"
((reverse("llo")) + "e") + "H"
(((reverse("lo")) + "l") + "e") + "H"
((((reverse("o")) + "l") + "l") + "e") + "H"
(((("o") + "l") + "l") + "e") + "H"
"olleH"
Interested in Java? Check out this Java Certification by Intellipaat.