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
09:28
C++ Program to Reverse a String - GeeksforGeeks | Videos
11:53
Reverse String in Java Practice Program - YouTube
Reverse string without using any temporary variable ...
Reverse Strings in JAVA | (simple & easy)
04:09
Java Program #7 - Reverse a String in Java - YouTube
19:58
Frequently Asked Java Program 03: Reverse A String | 3 Ways of ...
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
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
TutorialsPoint
tutorialspoint.com › home › javaexamples › java string reverse example
How to Reverse a String in Java
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
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
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();
Scaler
scaler.com › home › topics › reverse a string in java
Reverse a String in Java - Scaler Topics
March 14, 2024 - This tutorial demonstrates how to reverse a string in Java, useful for palindrome checks. For instance, reversing "Scaler" results in "relacS", showing character inversion. A classic palindrome example is "aibohphobia", humorously referring to the fear of palindromes, illustrating a string ...
coderolls
coderolls.com › reverse-a-string-in-java
How To Reverse A String In Java (5 ways) - Coderolls
December 2, 2019 - Print the reversedString. I have given the program as per the above logic. /** * A Java program to reverse a string. * * We are using 'toCharArray' method of the String class to get char array of the specified string * and append it with the temp string in reverse order.
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 - This technique is one of the simplest ways to reverse a string in Java by using a for loop. We can iterate through the characters of the string from the end to the beginning, and add them to a new string variable. Here is an example of how to reverse a string using a for loop: