Horje
reverse string using recursion java with explanation Code Example
reverse string using recursion java with explanation
public static String reverse(String str) {
    if ((null == str) || (str.length() <= 1)) {
        return str;
    }
    return reverse(str.substring(1)) + str.charAt(0);
}
reverse string using recursion java with explanation
public static String reverse(String str) 
{
    if(str.length() == 0)
       return "";
    return str.charAt(str.length()-1) + reverse(str.substring(0,str.length()-1)); 
}
reverse string using recursion java with explanation
public class Test {

    private static int i = 0;

    public static void main(String args[]) {
        reverse("Hello");
    }

    public static String reverse(String str) {
        int localI = i++;
        if ((null == str) || (str.length()  <= 1)) {
            return str;
        }
        System.out.println("Step " + localI + ": " + str.substring(1) + " / " + str.charAt(0));
        String reversed = reverse(str.substring(1)) + str.charAt(0);

        System.out.println("Step " + localI + " returns: " + reversed);
        return reversed;
    }
}




Java

Related
how to compare current date and time with another date and time  in android Code Example how to compare current date and time with another date and time in android Code Example
string.join java 8 Code Example string.join java 8 Code Example
groovy ternary operator short form Code Example groovy ternary operator short form Code Example
string to int java Code Example string to int java Code Example
string array to stream Code Example string array to stream Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8