Reverse a String with Recursion in Java

In this post, we will see how to reverse a string with recursion in Java.   As seen in the previous post, we can easily reverse a string in Java using stack data structure. As stack is involved, we can easily convert the code to use recursion call stack. As String is immutable, we first …

Reverse a string using Stack in Java

In this post, we will see how to reverse a string using Stack in Java.   Following example illustrates how to reverse a string with the help of Stack data structure in Java. Below are the complete steps – Create an empty stack of characters.   Convert given String into character array using String.toCharArray() function …

Reverse a string using Java Collections Framework reverse() method

In this post, we will see how to reverse a string using Java Collections Framework reverse() method.   Following example illustrates how to use Collections.reverse() to reverse a string in Java. Below are the complete steps – Create an empty ArrayList of characters and initialize it with characters of the given string using String.toCharArray().   …

Reverse a string using character array in Java

In this post, we will see how to reverse a string using character array in Java.   We know that we cannot make any change in the String object as String is immutable in Java. But we can use a character array that can be modified easily – Create an empty character array of same …

Reverse a string using Byte Array in Java

In this post, we will see how to reverse a string using Byte Array in Java.   The idea is very simple. We convert the given string into bytes and then inplace rearranges the byte array. Finally, we convert the byte array back into the string.  

Download   Run Code Output: Reversed string …

Reverse a string in Java using + (string concatenation) operator

In this post, we will see how to reverse a string in Java using + (string concatenation) operator.   We can make use of String Concatenation operator + to reverse a string in Java by reading characters from the end of it and concatenating in the beginning of a new string. Please note that to …

Reverse a string using StringBuilder and StringBuffer in Java

In this post, we will see how to reverse a string using StringBuilder and StringBuffer in Java.   Following example illustrates how to use StringBuilder.reverse() method to efficiently reverse a string in Java.  

Download   Run Code Output: Reversed string is : thgileD eihceT   Alternativey, we can also use StringBuffer.reverse() method. Using …