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: StringBuilder objects are mutable, and their reverse() method reverses the content in-place, which is faster than manual looping. We can use character array to reverse a string. Follow Steps mentioned below: First, convert String to character array by using the built-in Java String class method toCharArray().
Published   October 14, 2025
🌐
Codecademy
codecademy.com › docs › java › stringbuilder › .reverse()
Java | StringBuilder | .reverse() | Codecademy
August 22, 2022 - The .reverse() method returns a modified StringBuilder object with its character sequence rearranged in the opposite order. This is the most straightforward way to reverse a string in Java.
Discussions

[JAVA] Is there a way to make this reverse method more efficient? Possibly requiring only one loop?
Why are you iterating from 0 to size and then have your calculation? You could directly iterate in the opposite direction Since you have index-based access to the list elements, you should be able to do an in-place swap via a third, temp element (single element, not a list). In this case, you only need a single loop and only need to iterate over half the list. More on reddit.com
🌐 r/learnprogramming
9
5
August 26, 2022
[java AP Computer science A] why isn’t my reverse method reversing the string?
You aren't concatting or appending the string in your reverse loop. You are replacing x with each iteration. The last iteration is word.substring(0); substring takes two parameters, a beginning and an end index. if you omit the end, word.substring(0) is equivalent to word. play around with substring here: https://compiler.javatpoint.com/opr/test.jsp?filename=SubstringExample string concatenation: https://www.baeldung.com/java-string-concatenation More on reddit.com
🌐 r/HomeworkHelp
35
352
September 9, 2023
Explanation for how this recursive method to reverse a string works (JAVA)
Try walking through it on paper. Here's an algorithm to follow: Reverse: input is "str". If str is blank, return blank. separate str into the first character, car, and the remaining characters, cdr. Invoke this algorithm with an input of cdr, label result "reversedCdr". Return reversedCdr + car. If you do this by hand, you'll see what's happening. Make sure to carefully track the stack. Here's an example. Reverse(str is "nab") str isn't blank, keep going car is "n", cdr is "ab". Call reverse(str is "ab") str isn't blank, keep going car is "a", cdr is "b" Call reverse(str is "a") str isn't blank, keep going car is "b", cdr is "" Call reverse(str is "") str is blank, return blank. Return "" + "b", "b" Return "b" + "a", "ba" Return "ba" + "n", "ban" More on reddit.com
🌐 r/learnprogramming
3
5
February 21, 2021
The use of Java's Reverse() method
Easiest way I can currently think of would be to just do (n < 0 ? -1 : 1) * Integer.parseInt(String.valueOf(Math.abs(n)).reverse()) More on reddit.com
🌐 r/learnprogramming
9
2
July 16, 2020
🌐
Medium
medium.com › @AlexanderObregon › javas-stringbuilder-reverse-method-explained-b2b701ee2029
Java’s StringBuilder.reverse() Method Explained | Medium
October 3, 2024 - One method that comes in handy when manipulating strings is reverse(), part of the StringBuilder class in the java.lang package. This method allows you to reverse the order of characters in a string, a useful operation for various tasks such ...
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › stringbuilder reverse method in java
StringBuilder reverse Method in Java
September 1, 2008 - The Java StringBuilder reverse() method is used to reverse the characters of a StringBuilder object. It replaces the sequence of characters in reverse order.
🌐
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 - Next, the ‘Collections.reverse()’ method reverses the character list. Lastly, the reversed character list converts back to a string using a StringBuilder class and another iterative for-each loop.
🌐
Quora
quora.com › How-can-a-string-be-reversed-in-Java
How can a string be reversed in Java? - Quora
Answer (1 of 3): // Sample program: import java.lang.*; // java.lang.System && java.lang.StringBuilder class StringReverse { public static void main(String[] args) { String network_search = "lssnepo nasegurum"; System.out.println( "My network_search: " + new StringBuilder( network_search )...
Find elsewhere
🌐
W3Schools
w3schools.com › java › java_howto_reverse_string.asp
Java How To Reverse a String
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
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
🌐
Scaler
scaler.com › home › topics › reverse a string in java
Reverse a String in Java - Scaler Topics
March 14, 2024 - Use the toCharArray() method to convert the input string into a character array. Iterate over the character array in reverse order. Append each character to a StringBuilder or concatenate to a new string to form the reversed string. ... Using ArrayList objects to reverse a string in Java involves converting the string into a collection of characters, reversing the collection, and then constructing the reversed string from the collection.
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › how to reverse a string in java
How to Reverse a String in Java | Interview Kickstart
September 25, 2024 - In this method, we use the reverse() method and ArrayList object of Java to reverse the string. First, we add each of the string characters into the ArrayList object. We’ll pass this ArrayList object to the reverse() method to get it reversed. Then we iterate over the ArrayList and push all characters in StringBuilder.
Address   4701 Patrick Henry Dr Bldg 25, 95054, Santa Clara
(4.7)
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-reverse-method-in-java
StringBuffer reverse() Method in Java with Examples - GeeksforGeeks
August 4, 2022 - The Java.lang.StringBuffer.reverse() is an inbuilt method that is used to reverse the characters in the StringBuffer. The method causes this character sequence to be replaced by the reverse of the sequence.
🌐
CodeGym
codegym.cc › java blog › random › different ways to reverse a string in java
Different Ways to Reverse a String in Java
February 1, 2023 - We can also reverse the string in Java by using the StringBuilder class. The StringBuilder class provides a reverse() method that can be used to reverse a string. The reverse() method of the Java StringBuilder class is used to replace this character sequence with the reverse of the sequence.
🌐
Reddit
reddit.com › r/learnprogramming › [java] is there a way to make this reverse method more efficient? possibly requiring only one loop?
r/learnprogramming on Reddit: [JAVA] Is there a way to make this reverse method more efficient? Possibly requiring only one loop?
August 26, 2022 -
//code inside a reverse method that has the list object 
//passed as a parameter from main method
int size = list.size();
//create temporary list object to hold contents of original list in reverse
MyListReferenceBased temp = new MyListReferenceBased(); 
for (int i = 0; i < size; i++) 
{ 
//list add method requires which index your adding to, and object
//get method just gets the object at the specified index in list
temp.add(i, list.get((size-i)-1)); 
//remove method just removes object at specified index
list.remove((size-i)-1);                       
} 
//now that original list is empty, put the contents back in 
for (int i = 0; i<size; i++)
{ 
list.add(i, temp.get(i));            
} 
temp.removeAll(); 
//end result: original list is now reversed and temporary array is all empty 
System.out.println("List has been Reversed."); 
//is there a way to get rid of the 2nd loop?? Not possible to just assign?

So this code is in a reverse method inside the main class for reversing a linked list. Well reversing a list in general, since the user of the main class isn't suppose to interact with the linked list directly but just has access to the linked list methods (Didn't do reverse inside linked list class on purpose). Rather in the main/driver class, I'm reversing the list by first creating a second/temporary linked list, adding over each of the elements from the original list (in reverse) into the new list. And then since I need the contents to be in the original list and only need the temporary list during the duration of this method, I copy over the elements back into the old list.

The list object is instantiated as local in the main method of this main class and then calls the reverse method, passing the list object as a parameter. Instead of having the second loop, isn't there a way to just assign the temporary list object to the original list? I was able to do this when I the underlying implementation of the list was using arrays, but not sure how to it with linked lists.

Or any other efficient work around? Remember this is specifically for reversing a linked list without directly being inside the linked list class.

🌐
Educative
educative.io › answers › how-to-reverse-a-string-in-java-without-using-stringreverse
How to reverse a string in Java without using String.reverse()
Line 3: We define the reverse() method. Line 5: We perform a Null check. Line 7: We create an instance of the StringBuilder class.
Top answer
1 of 2
1
The previous solution given will work! I'm going to suggest some modifications. Here's the original:public static String reverse(String str) { String reversed = ""; for (int i = str.length() - 1; i >= 0; i--) { reversed += str.substring(i, i + 1); } return reversed;}That call to str.substring(i, i + 1) is essentially a way of picking out a single character at index i, but there's actually a built in String method for that: charAt. And I think things read a bit more easily using it. Using it is also a bit semantically clearer in my opinion (others can disagree!):public static String reverse(String str) { String reversed = ""; for (int i = str.length() - 1; i >= 0; i--) { reversed += str.charAt(i); } return reversed;}It's generally better to use a StringBuilder, though, since that keeps us from generating a lot of Strings along the way (what if our input String was a very long String)?public static String reverse(String str) { StringBuilder reversed = new StringBuilder(); for (int i = 0; i < str.length(); ++i) { reversed.insert(0, str.charAt(i)); } return reversed.toString();}Note that here, I actually iterated forward through the String and prepended (using insert), but you could iterate backwards and use the append method, too. But the main point is that using a StringBuilder keeps us from having to generate new Strings for each character in the input.I hope that helps!
2 of 2
0
We can't use a pre-defined function in java that can instantaneously reverse a string. Therefore, we must come up with a way to do so. One way we can do this is by creating a new string adding individual characters to it by traversing through the original string in reverse order. This will result in the final string being the reverse of the original string, and this will be our solution to the problem. An implementation of this solution looks like:public class MyClass {public static void main(String args[]) {String before="hello";String after=reverse(before);System.out.println(after);}public static String reverse(String str){String reversed="";for(int i=str.length()-1; i>=0; i--){reversed+=str.substring(i,i+1);}return reversed;}}
🌐
TutorialsPoint
tutorialspoint.com › home › java/util › java collections reverse
Java Collections reverse() Method
September 1, 2008 - The Java Collections reverse(List<?>) method is used to reverse the order of the elements in the specified list.
🌐
Programiz
programiz.com › java-programming › examples › reverse-number
Java Program to Reverse a Number
Become a certified Java programmer. Try Programiz PRO! ... class Main { public static void main(String[] args) { int num = 1234, reversed = 0; System.out.println("Original Number: " + num); // run loop until num becomes 0 while(num != 0) { // get last digit from num int digit = num % 10; reversed = reversed * 10 + digit; // remove the last digit from num num /= 10; } System.out.println("Reversed Number: " + reversed); } }
🌐
Baeldung
baeldung.com › home › java › java list › reverse an arraylist in java
Reverse an ArrayList in Java | Baeldung
April 3, 2025 - Next, let’s see them in action. The Java standard library has provided the Collections.reverse method to reverse the order of the elements in the given List.