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.

Answer from Daniel Brockman on Stack Overflow
🌐
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
People also ask

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]
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › reverse-a-string-in-java
Reverse a String in Java? - A Complete Guide
In the above example, a new string called 'reversed' is being created, and then a loop is used to repeat over the characters of the original string 'str' from the end to the beginning.
🌐
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 = ...
🌐
Baeldung
baeldung.com › home › java › java string › how to reverse a string in java
How to Reverse a String in Java | Baeldung
January 8, 2024 - In this tutorial, we’ve first looked at different ways of reversing a String in Java. We went through some examples using core Java and a popular third-party library like Apache Commons.
🌐
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
Find elsewhere
🌐
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
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java reverse string: tutorial with programming examples
Java Reverse String: Tutorial With Programming Examples
April 1, 2025 - As the name suggests, the reverse() method is used to reverse the order of occurrences of all the characters of a String. ... In this example, we have initialized a String variable and stored all the characters of that String into StringBuffer.
🌐
LogicMojo
logicmojo.com › reverse-a-string-in-java
Reverse a String in Java- Logicmojo
The basic condition of the function will be; if the string is null or length less than or equal to one then return the original string, else, print the last character of the string and recursively call the function.
🌐
Sololearn
sololearn.com › en › Discuss › 2805778 › how-to-reverse-a-string-in-java
How to reverse a string in java | Sololearn: Learn to code for FREE!
If you prefer not to use an array and keep it simple with just Strings, then: String myWord = "abc"; String reversed = ""; for (int i = myWord.length() - 1; i >= 0; i--) reversed += myWord.charAt(i); System.out.println(reversed);
🌐
Medium
medium.com › womenintechnology › 3-ways-to-reversing-string-in-java-b40a23bbcc6c
3 ways to Reversing String In JAVA | by Daily Debug | Women in Technology | Medium
August 10, 2023 - String reveresed = str.chars()... they ask to reverse a sentence without disturbing its sequence. For example Input — Reverse this string....
🌐
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
(4.7)
🌐
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.
🌐
ScholarHat
scholarhat.com › home
How To Reverse A String In Java: Explained
September 9, 2025 - Add each character to a new string ... StringBuilder(); while (!stack.isEmpty()) { reversed.append(stack.pop()); } System.out.println("Reversed String: " + reversed.toString()); } }...
🌐
Hero Vired
herovired.com › learning-hub › blogs › reverse-a-string-in-java
How to Reverse a String in Java Using for Loop | Hero Vired
The for loop iterates up to the end of the string index zero. This approach to reverse a string in Java can employ the in-built reverse() method to receive your intended output. The code below will help you understand how to reverse a java string ...
🌐
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();