The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Re: Recursive Program for String Reversal

Posted by hotboy on August 07, 2001 at 5:09 AM

> Hai guys,
> This is Deepa who is appearing for the first time in this forum. Can any one of u guys provide me the code for reversal of String using a Recursive Function?

> Thank u,
> Deepa.

If you have to use recursion, you may mean something like this. I didn't test it and you will sure need to refine it to make it work for all cases.

String ReversString(String str, int length) {
String tmpstr;
if (length > 1 ) {
tmpstr = str.charAt(length - 1) + ReversString(str.substring(1, length - 2), length - 2) + str.charAt(0);
return tmpstr;


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us