You can use this:
new StringBuilder(hi).reverse().toString()
StringBuilder was added in Java 5. For versions prior to Java 5, the StringBuffer class can be used instead — it has the same API.
GeeksforGeeks
geeksforgeeks.org › java › reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
Explanation: Characters are stored in a list and reversed using Collections.reverse(). This approach is helpful when you’re already working with Java collections. StringBuffer is similar to StringBuilder but thread-safe.
Published October 14, 2025
Top answer 1 of 16
1224
You can use this:
new StringBuilder(hi).reverse().toString()
StringBuilder was added in Java 5. For versions prior to Java 5, the StringBuffer class can be used instead — it has the same API.
2 of 16
128
For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:
public static String reverse(String input){
char[] in = input.toCharArray();
int begin=0;
int end=in.length-1;
char temp;
while(end>begin){
temp = in[begin];
in[begin]=in[end];
in[end] = temp;
end--;
begin++;
}
return new String(in);
}
Videos
11:28
How to reverse a String in java using recursion? - YouTube
11:53
Reverse String in Java Practice Program - YouTube
10:26
How to Reverse a String in Java - YouTube
19:58
Frequently Asked Java Program 03: Reverse A String | 3 Ways of ...
01:00
Java Program to Reverse String without using in-built reverse() ...
04:09
Java Program #7 - Reverse a String in Java - YouTube
What is a String in Java?
Strings in Java are immutable (cannot be modified or changed) non-primitive data types that store a sequence of characters.
hackr.io
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
How Many Ways Can You Reverse a String in Java?
You can use iterative methods that create new String objects to store a reversed string, or methods that swap the current leftmost and rightmost String characters via a temporary variable. Alternatively, you can use the StringBuffer and StringBuilder classes to access a built-in reverse() function, or use the Collections class to access a reverse() method for List data structures. You can also use recursion, or a Stack object to take advantage of its LIFO property to reverse characters. Finally, you can also use a third-party library like Apache Commons.
hackr.io
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
What is the Reverse Method in Java?
When dealing with String objects, there is no reverse method. But, if we can use the StringBuffer or StringBuilder classes we can use a built-in reverse() method. This is allowed because these classes are mutable.
hackr.io
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
W3Schools
w3schools.com › java › java_howto_reverse_string.asp
Java How To Reverse a String
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
TutorialsPoint
tutorialspoint.com › home › javaexamples › java string reverse example
Java String Reverse Example
September 1, 2008 - The following is an example of reversing a string by using toCharArray() method · import java.io.*; import java.util.*; public class HelloWorld { public static void main(String[] args) { String input = "tutorialspoint"; char[] try1 = ...
FavTutor
favtutor.com › blogs › reverse-string-java
Reverse a String in Java (with Examples)
September 28, 2024 - Using this method, we will instantiate a Stack object of characters and push all the characters of the original string into the stack using the stack’s inbuilt function push(). Since stack follows the principle of “First In Last Out”, characters will be popped out the characters in reversed order. Hence, we will create a new string and pop all characters from the stack, and concatenate them in the new string as shown in the below example ... import java.util.Stack; public class ReverseStringByFavTutor { public static void main(String[] args) { String stringExample = "FavTutor"; System.ou
Simplilearn
simplilearn.com › home › resources › software development › how to reverse a string in java: 12 best methods
How to Reverse a String in Java: 12 Best Methods
May 5, 2025 - How to Reverse a String in Java? 1. Using toCharArray() 2. Using StringBuilder 3. Using While Loop/For Loop 4. Converting a String to Bytes 5. Using ArrayList
Address 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
Hackr
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
January 30, 2025 - In this example we use the StringBuffer class and its built-in reverse() method to quickly return the reverse of a string in Java. This is similar to the StringBuilder approach in method 3 as the StringBuffer is also mutable (can be altered ...
Javatpoint
javatpoint.com › how-to-reverse-string-in-java
How to Reverse String in Java - javatpoint
Java Program to prove that strings are immutable in java · Java program to reverse a given string with preserving the position of spaces
Interview Kickstart
interviewkickstart.com › home › blogs › learn › how to reverse a string in java
How to Reverse a String in Java | Interview Kickstart
First, we’ll create a temporary byte array whose length will be equal to the length of the string, and then we’ll store the string in byte form in a reverse manner in that byte array. Now, we again convert it into the string and simply print it. ... Collection class in Java has a built-in reverse() method to reverse the object.
Address 4701 Patrick Henry Dr Bldg 25, 95054, Santa Clara
Emeritus
emeritus.org › home › blog › information technology › 9 most convenient ways to reverse a string in java
9 Most Convenient Ways to Reverse a String in Java
September 24, 2024 - The following are the nine most convenient ways to reverse a string in Java. Firstly, you must create a new empty string to accommodate the reversed string in this method. Then, you must add each character of the original string in reverse order to the new empty string. ... In the above example, the input is the original string ‘Hello, World’. ‘Reversed’ is the new empty string created to accommodate the reversed string.
Codecademy
codecademy.com › docs › java › stringbuilder › .reverse()
Java | StringBuilder | .reverse() | Codecademy
August 22, 2022 - Returns a modified StringBuilder object with its character sequence rearranged in the opposite order.
Programming Simplified
programmingsimplified.com › java › source-code › java-program-reverse-string
Reverse a string in Java | Programming Simplified
class ReverseString { public static void main(String args[]) { String original, reverse = ""; Scanner in = new Scanner(System.in); System.out.println("Enter a string to reverse"); original = in.nextLine();