Hi, I have been messing around with recursion today. Often a programming technique that is not used enough.
So.. I set myself the task to recursively reverse a string, heres what I came up with :
//A method to reverse a string using recursion
public String reverseString(String s){
char c = s.charAt(s.length()-1);
if(s.length() == 1) return Character.toString(c);
return c + reverseString(s.substring(0,s.length()-1));
}
My question is there a better way in Java?
Thanks for the replies :-)