reverse string using recursion java with explanation
Java
public static String reverse(String str) {
if ((null == str) || (str.length() <= 1)) {
return str;
}
return reverse(str.substring(1)) + str.charAt(0);
}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;
}
}
Also in Java:
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- java interface
- Category
- Java
- Title
- bootstrap center text vertically
- Category
- Java
- Title
- padding a string with 0 in java
- Category
- Java
- Title
- count word in string no matter the delimiter java
- Category
- Java
- Title
- uppercase java
- Category
- Java
- Title
- final variables in java
- Category
- Java
- Title
- iterate map in java 8 using stream
- Category
- Java
- Title
- apt install java 11
- Category
- Java
- Title
- java array to list
- Category
- Java
- Title
- how to get individual words from a string in java
- Category
- Java
- Title
- reverse a string in java
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- mkyong restful web services spring boot examples post
- Category
- Java
- Title
- loop and save letters in a string java
- Category
- Java
- Title
- java how to stop code
- Category
- Java
- Title
- index 1 out of bound for length 1 java
- Category
- Java
- Title
- google map set default zoom android studio
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- icon label java
- Category
- Java
- Title
- how to create an array with unique values
- Category
- Java
- Title
- nikita kaksharov
- Category
- Java
- Title
- How to chage font progrmatically
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- expression régulière seulement un espace java
- Category
- Java
- Title
- print values of bst java
- Category
- Java
- Title
- how to print ascii value in java
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- java convert a string to char[]
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- thread sleep java
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- java int array
- Category
- Java
- Title
- float to string java
- Category
- Java
- Title
- java write arraylist of objects to file
- Category
- Java
- Title
- java class array of objects
- Category
- Java
- Title
- discord jda remove @everyone from channel
- Category
- Java
- Title
- java for increment by 2
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- how to initialize an array in java
- Category
- Java
- Title
- how to push an element in hashset java
- Category
- Java
- Title
- java jaxb unmarshall xml to map
- Category
- Java
- Title
- how to format a datetime object to show date and time and milliseconds in java
- Category
- Java
- Title
- get first 5 characters of string java
- Category
- Java
- Title
- java replace element in list
- Category
- Java
- Title
- how to use for loop for array in java
- Category
- Java
- Title
- java fx display simple rectangle
- Category
- Java
- Title
- java int passed by reference
- Category
- Java
- Title
- how to change actionbar color in android programmatically
- Category
- Java
- Title
- parallel sorting in java 8
- Category
- Java
- Title
- java string to integer
- Category
- Java
- Title
- java 8 find min value in array
- Category
- Java
- Title
- how to separate no and text in java
- Category
- Java
- Title
- print a string java
- Category
- Java
- Title
- check if string is null or empty java
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- html top padding
- Category
- Java
- Title
- java 8 retrieve all list from object into single list and ignore duplicates
- Category
- Java
- Title
- android create snackbar
- Category
- Java
- Title
- remove part of string java
- Category
- Java
- Title
- initialiser une arraylist
- Category
- Java
- Title
- add a value to a list java in java hashmap
- Category
- Java
- Title
- hashmap in java
- Category
- Java
- Title
- java manacher's algorithm
- Category
- Java
- Title
- java boolean even number
- Category
- Java
- Title
- java array check duplicates
- Category
- Java
- Title
- java for in loop
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- how to declare string array in java
- Category
- Java
- Title
- check if string is decimal java
- Category
- Java
- Title
- check if value exists in hashset java
- Category
- Java
- Title
- use regex in if statement java
- Category
- Java
- Title
- Caused by: java.lang.NumberFormatException: Invalid int: ""
- Category
- Java
- Title
- how to set a variable java
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- java android edit text set value
- Category
- Java
- Title
- java random seed
- Category
- Java
- Title
- java initialize string array
- Category
- Java
- Title
- java flood fill
- Category
- Java
- Title
- test function that call a function javascrip
- Category
- Java
- Title
- import classes from another project java
- Category
- Java
- Title
- how to change the icon of a jframe
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- immagini java
- Category
- Java
- Title
- java insert new line in string
- Category
- Java
- Title
- how to find substring in java
- Category
- Java
- Title
- how to break from a loop in java
- Category
- Java
- Title
- converter int array para string java
- Category
- Java
- Title
- java nextpermutation
- Category
- Java
- Title
- using java 8 stream to process data in java
- Category
- Java
- Title
- java queue
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- validate request body java
- Category
- Java
- Title
- java best way to concatenate strings
- Category
- Java
- Title
- list java oracle
- Category
- Java
- Title
- index of an array procesing
- Category
- Java
- Title
- do statement java
- Category
- Java
- Title
- java io
- Category
- Java