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
It’s a common programming task used in algorithms, data processing, and interviews. There are several ways to reverse a string in Java, from using loops to built-in methods. The for loop is the most basic and manual approach.
Published   October 14, 2025
People also ask

Is There a Method to Reverse a String in Java?
The Java String class does not have a built-in method to directly reverse a string. Instead, you can use the StringBuffer or StringBuilder classes which offer a reverse() function. Alternatively, you also can use other algorithms and data structures to reverse a string without these methods.
🌐
hackr.io
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
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]
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]
🌐
Hackr
hackr.io › home › articles › programming
How to Reverse a String in Java: 9 Ways with Examples [Easy]
January 30, 2025 - This tutorial covers 9 methods for how to reverse a string in Java, including methods using built-in reverse functions, recursion, and a third-party library.
🌐
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
🌐
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 - Therefore, you need to create a new string to reverse an existing string. Programmers can perform various operations using a string. However, reversing a string is one of the most widely used functions in Java programming. The following are the nine most convenient ways to reverse a string in Java.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › reverse-a-string-in-java
How to Reverse a String in Java with Examples
XOR operation is not generally used to reverse a string in Java. The most common way to reverse a string in Java is by using the 'StringBuilder' class or by iterating through the characters in the string and reversing them manually.
🌐
FavTutor
favtutor.com › blogs › reverse-string-java
Reverse a String in Java (with Examples)
September 28, 2024 - Learn how to reverse a string in java. We have introduced a detailed guide to java reverse string using 9 methods and examples.
Find elsewhere
🌐
Javatpoint
javatpoint.com › how-to-reverse-string-in-java
How to Reverse String in Java - javatpoint
There are many ways to reverse String in Java. We can reverse String using StringBuffer, StringBuilder, iteration etc. Let's see the ways to reverse String in Java.
🌐
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
🌐
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 - ... char [] strCharArray = str.toCharArray() ; StringBuffer revr = new StringBuffer(); for(int i=strCharArray.length-1;i>-1;i--){ revr.append(strCharArray[i]); } System.out.println("Reversed String : "+revr);
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › reverse a string in java
Reverse a String in Java | 10 Best Methods with Code
October 24, 2025 - Learn 10 efficient ways to reverse a string in Java. Includes code examples, output, explanations, and performance tips for beginners and interview prep.
🌐
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 - In the fifth method, we used the stream API and the java collector to reverse the string and, In the last method we used the stack to reverse the string in java. Each of these methods has its advantages and disadvantages, and the choice of method depends on the specific requirements of the problem and the programmer’s preference. Overall, these methods demonstrate the flexibility and versatility of Java in string manipulation.
🌐
coderolls
coderolls.com › reverse-a-string-in-java
How To Reverse A String In Java (5 ways) - Coderolls
December 2, 2019 - So we have seen all five ways to reverse the string in Java.
🌐
Scientech Easy
scientecheasy.com › home › blog › reverse string in java with program
Reverse String in Java with Program - Scientech Easy
June 2, 2025 - Learn how many ways to reverse a string in Java by character and word, reverse a string using for loop, StringBuffer/StringBuilder, recursion
🌐
Crunchify
crunchify.com › interview questions answers › how to reverse a string in java? total 7 different ways…
How to Reverse a String in Java? Total 7 different ways... • Crunchify
February 1, 2021 - package crunchify.com.tutorials; import org.apache.commons.lang3.StringUtils; import java.nio.charset.StandardCharsets; /** * @author Crunchify.com * How to Reverse a string in Java? * Version: 2.0 */ public class CrunchifyReverseString { public static void main(String[] args) { String testString = "Crunchify.com Example"; System.out.println("String: " + testString); System.out.println("\nSolution1: Reverse Using reverseStringBuffer: " + reverseStringBuffer(testString)); System.out.println("Solution2: Reverse Using reverseCharArray: " + reverseCharArray(testString)); System.out.println("Soluti
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › reverse string in java
Reverse String in Java | Using Various Methods with Examples
January 8, 2024 - Several operations can be performed on the String object in Java. One of the commonly used operations is String Reversal. A String that is reversed is said to be a Reverse String. For example, the ‘HAPPY’ string can be reversed as’ YPPAH’. Similarly, the ‘LUCKY’ string can be written as ‘YKCUL’ when it is reversed. ... There are several ways in which a string can be reversed.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai