Suppose, you have a String "Hello" then it will perform the recursion over the string starting from left to right.
char c = s.charAt(0);
return reverseString(s.substring(1)) + c;
1) for H
c = 'H'
return reverseString("ELLO") + H
2) For E
c = 'E'
return reverseString("LLO") + E
3) for E
c = 'E'
return reverseString("LLO") + E
4) for L
c = 'L'
return reverseString("LO") + L
5) for L
c = 'L'
return reverseString("O") + L
6) Since, substring s<= 1
return S = 'O'
7) Now it will resume back the recursive functions from bottom to top and will concatenate
all the string s at each level
So, O + L + L + E + H = "OLLEH"
BTW, In java, string reversal is a cakewalk using StringBuilder/StringBuffer.
e.g. StringBuffer("Hello".toReverse()).toString();
If you are using single threaded and simpler applications, go with StringBuilder
For, concurrent complex applications go with StringBuffer, its Synchrinized.
Hope, it helps.