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
In Java, reversing a string means rearranging its characters from last to first. It’s a common programming task used in algorithms, data processing, and interviews.
Published October 14, 2025
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
Videos
10:01
String Reverse in Java | Part 1 | Using Loop (Beginner Friendly) ...
04:09
Java Program #7 - Reverse a String in Java - YouTube
Reverse A String (Java Tutorial) - YouTube
01:01
Java Reverse Loop | Java Tutorial - YouTube
06:28
Java Program #12 - Reverse a Number in Java - YouTube
01:00
Java Program to Reverse String without using in-built reverse() ...
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);
}
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.
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
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); } }
Vultr Docs
docs.vultr.com › java › examples › reverse-a-number
Java Program to Reverse a Number | Vultr Docs
April 10, 2025 - In this code, as long as the number is not zero, the last digit is peeled off using the modulus operation, added to the reverse, and the original number is reduced by dividing by 10. This loop effectively places the last digit of the number at the front, achieving the reverse of a number in Java.
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.
GeeksforGeeks
geeksforgeeks.org › java › collections-reverse-method-in-java-with-examples
Collections.reverse() Method in Java with Examples - GeeksforGeeks
Note: It does not sort the elements, it simply reverses their current order. This class is present in java.util package so the syntax is as follows:
Published July 23, 2025
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 - In the above example, a for-each iterative loop converts the input string into a list of characters. 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
GeeksforGeeks
geeksforgeeks.org › java › java-reverse-number-program
Reverse Number Program in Java - GeeksforGeeks
In Java, reversing a number means that the digit at the first position should be swapped with the last digit, the second digit will be swapped with the second last digit, and so on, till the middle element.
Published July 23, 2025
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.
GeeksforGeeks
geeksforgeeks.org › java › reverse-an-array-in-java
Reverse an Array in Java - GeeksforGeeks
July 11, 2025 - When we are working with a String array, we can use a StringBuilder and append each array element with a for loop decrementing from the array's length, then convert the StringBuilder to a string, and split back into an array. ... // Java Program for Reversing an array // using StringBuilder import java.util.Arrays; class Geeks { public static void main (String[] args) { String[] arr = {"Hello", "World"}; StringBuilder r = new StringBuilder(); for (int i = arr.length; i > 0; i--) { r.append(arr[i - 1]).append(" "); }; String[] ra = r.toString().split(" "); System.out.println(Arrays.toString(ra)); } }
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-reverse-in-java-with-examples
StringBuilder reverse() in Java with Examples - GeeksforGeeks
January 22, 2026 - The reverse method of the StringBuilder class is used to reverse the sequence of characters in a StringBuilder object.
Naukri
naukri.com › code360 › library › reverse-a-string-in-java
Java Reverse String: Methods, Examples, and Code
November 11, 2025 - Almost there... just a few more seconds
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!
June 7, 2021 - Narashima Murthy, In case you didn't know what tags in the forum is for https://code.sololearn.com/W3uiji9X28C1/?ref=app ... 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);
CodeGym
codegym.cc › java blog › strings in java › reverse a string in java
Reverse a String in Java
October 11, 2023 - “Start reading a String beginning from its last character all the way up to the first character. Bingo! that was your reversed string." Here’s a demonstration of how it will look like. Input String = "X Y Z"; Output String = "Z Y X" Input String = "1 2 3"; Output String = "3 2 1"; Input String = "I love Java!"; Output String = "!avaJ evol I";