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-words-given-string-java
Reverse words in a given String in Java - GeeksforGeeks
January 22, 2026 - Input: "Welcome to geeksforgeeks" ... between words and at the start or end of the string · Step 1: Split the string into words using a regex pattern for whitespace....
🌐
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. ALSO READ: Here Are 5 Important Reasons to Learn Java Programming in 2024
Discussions

Reverse a string in Java - Stack Overflow
I have "Hello World" kept in a String variable named hi. I need to print it, but reversed. How can I do this? I understand there is some kind of a function already built-in into Java that does th... More on stackoverflow.com
🌐 stackoverflow.com
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
how to reverse a string in java
Write down a short string on a piece of paper and reverse the string by hand. How do you do that? More on reddit.com
🌐 r/learnprogramming
11
1
April 4, 2021
String Reverse without for loop or utility methods (Java)

Use recursion instead if for loop.

More on reddit.com
🌐 r/learnprogramming
17
12
March 19, 2012
🌐
Medium
medium.com › @AlexanderObregon › javas-stringbuilder-reverse-method-explained-b2b701ee2029
Java’s StringBuilder.reverse() Method Explained | Medium
October 3, 2024 - In Java, working with strings efficiently is an important skill for any developer. 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 as checking palindromes or reversing data streams.
🌐
Hero Vired
herovired.com › learning-hub › blogs › reverse-a-string-in-java
How to Reverse a String in Java Using for Loop | Hero Vired
March 19, 2024 - When you reverse a string in Java, it will change the order of a given string. The change will ensure that the last character of the Java string becomes the first one. Additionally, a Java program to reverse a string also enables you to check the Palindrome of the given string.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › reverse-a-string
Reverse a String – Complete Tutorial - GeeksforGeeks
// Java program to reverse a string using backward traversal class GfG { static String reverseString(String s) { StringBuilder res = new StringBuilder(); // Traverse on s in backward direction // and add each character to a new string for (int i = s.length() - 1; i >= 0; i--) { res.append(s.charAt(i)); } return res.toString(); } public static void main(String[] args) { String s = "abdcfe"; String res = reverseString(s); System.out.print(res); } } Python ·
Published   3 days ago
🌐
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
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
🌐
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
🌐
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 - We’ll start to do this processing using plain Java solutions. Next, we’ll have a look at the options that third-party libraries like Apache Commons provide. Furthermore, we’ll demonstrate how to reverse the order of words in a sentence. We know that strings are immutable in Java.
🌐
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
🌐
Reddit
reddit.com › r/learnprogramming › explanation for how this recursive method to reverse a string works (java)
r/learnprogramming on Reddit: Explanation for how this recursive method to reverse a string works (JAVA)
February 21, 2021 -
public String reverse(String str) {
    if(str.length()==0){
        return str;
    }
    else{
        return reverse(str.substring(1))+str.charAt(0);
    }
}

I was wondering how recursive methods work. What causes this method continue to plug itself back into the function? When does str.length==0 and why does it end up returning a reversed string rather than a blank in my main method.

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;}}
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
🌐
Quora
quora.com › How-do-I-reverse-a-String-in-Java-without-using-any-loop-or-inbuilt-methods
How to reverse a String in Java without using any loop or inbuilt methods - Quora
Answer (1 of 15): If not iterative then do it recursive! Mostly every iterative problem can be converted to recursive with some paper work! [code]String reverse(String s) { if(s.length() == 0) return ""; return s.charAt(s.length() - 1) + reverse(s.substring(0,s.length()-1)); } [/code]
🌐
Medium
medium.com › @thurumerla.venkatesh › 5-ways-to-reverse-a-string-in-java-without-using-reverse-or-sort-methods-66bc995a5cc9
10 Different Ways to Reverse a String in Java (Without using reverse or sort methods) | by Thurumerla Venkatesh | Medium
February 19, 2024 - This method iterates through the string’s characters in reverse order using IntStream, appending each character to a StringBuilder. It's clear and readable, but may not be the most efficient for large strings. import java.util.stream.IntStream; public class ReverseString { public static String reverse(String str) { StringBuilder sb = new StringBuilder(); for (int i = str.length() - 1; i >= 0; i--) { sb.append(str.charAt(i)); } return sb.toString(); } public static void main(String[] args) { String input = "Hello, World!"; String reversed = reverse(input); System.out.println("Original: " + input); System.out.println("Reversed: " + reversed); // !dlroW ,olleH } }
🌐
Reddit
reddit.com › r/learnprogramming › how to reverse a string in java
r/learnprogramming on Reddit: how to reverse a string in java
April 4, 2021 -

hey guys i need your help in java so i have a very beginner problem and i'll probably be laughed at for asking this but how do you reverse a string in java

so far the online called I've been given to work with is:

import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine();
char[] arr = text.toCharArray();

//your code goes here

}
}

i don't know how to go about it, all i have to do is reverse the string. uhg it was so easy in python with just the (::-) is that how its written idk it's been some time python.

anyways i would appreciate any help and advice on learning java effectively i don't know much yet, i tried going on leetcode but daaaaamn it was crazy hard, i didn't manage to do any problem. thank you

🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.
🌐
JanBask Training
janbasktraining.com › community › java › reverse-a-string-in-java
Reverse a string in Java | JanBask Training Community
September 14, 2025 - In short, the most recommended method is using StringBuilder.reverse(), as it is concise and efficient. However, understanding loop-based or array-based methods is useful for interviews and strengthening your grasp of Java fundamentals.