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: 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 ย  May 12, 2026
๐ŸŒ
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
Discussions

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
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 - A simple way!
Step 1, uninstall Java More on reddit.com
๐ŸŒ r/coding
1
0
April 29, 2020
Reversing a String
import java.io.FileNotFoundException;

import java.io.PrintStream; import java.util.*; import java.io.File;

public class ReverseString

{ public static void main(String[] args) throws FileNotFoundException {

	String line = ""; // This would be what is needed for the output.
						// The changes made from the input to the output file.

	Scanner s = new Scanner(new File("input.txt"));
	if (s.hasNextLine()) {
		line = s.nextLine(); // Read the first line without adding a newline character
	}
	while (s.hasNextLine()) {
		line = line + "\n" + s.nextLine(); // Add a newline character before each subsequent line
	}

	// Store the length of the string.
	int length = line.length();

	// Create a string that will store the reversed sequence of characters (string).
	String reversedString = "";

	/*
	 * for loop that begins at the end of the string, storing the characters in the
	 * "reversedString" until every index of the string has been reached (or the
	 * length is less than 0). The loop runs until the case is not true.
	 */
	for (int i = length - 1; i >= 0; i--) {
		reversedString = reversedString + line.charAt(i);
	}

	// print fully reversed string.
	System.out.println(reversedString);

	PrintStream PS = new PrintStream(new File("output.txt"));
	PS.println(reversedString);
}

}

If the code image did not attach as it should have, here is the code^

More on reddit.com
๐ŸŒ r/JavaProgramming
3
3
February 21, 2024
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-stringbuilder-reverse-method-explained-b2b701ee2029
Javaโ€™s StringBuilder.reverse() Method Explained | Medium
October 3, 2024 - Another common use case for StringBuilder.reverse() is reversing text streams, which can be useful in certain types of data processing. For example, you might need to reverse logs, output text in reverse order, or transform data streams in scenarios like network communication or file reading. Consider the following example where we reverse user input: import java.util.Scanner; public class ReverseStreamExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a line of text:"); String input = scanner.nextLine(); StringBuilder sb = new StringBuilder(input); System.out.println("Reversed: " + sb.reverse().toString()); } }
๐ŸŒ
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

๐ŸŒ
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 - Java also offers some mechanisms like StringBuilder and StringBuffer that create a mutable sequence of characters. These objects have a reverse() method that helps us achieve the desired result. Here, we need to create a StringBuilder from the String input and then call the reverse() method:
Find elsewhere
๐ŸŒ
The Knowledge Academy
theknowledgeacademy.com โ€บ blog โ€บ reverse-a-string-in-java
Reverse a String in Java? - A Complete Guide
May 14, 2026 - Finally, the console prints the reversed string. In Java, you can reverse a string using the 'StringBuffer' class. It provides a 'reverse()' method that can be used to reverse the order of characters of the string.
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.
๐ŸŒ
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 - out.println("Reversed String : "+str1.reverse()); Although we can use inbuilt Java methods to reverse the string, it is good to know alternatives of it, so letโ€™s check other ways to reverse a string without using inbuilt functions
๐ŸŒ
SkillVertex
skillvertex.com โ€บ blog โ€บ how-to-reverse-a-string-in-java
Reverse A String In Java
May 10, 2024 - One of the most efficient ways to reverse a string in Java is by using the StringBuilder class.
๐ŸŒ
ArtOfTesting
artoftesting.com โ€บ home โ€บ java โ€บ reverse a string in java
Reverse a String in Java | Java Program to Reverse a String
April 29, 2021 - The length() method returns an ... variable String reverse = ""; for(int i=length-1;i>=0;i--) reverse= reverse + str.charAt(i); System.out.println(reverse); } }...
๐ŸŒ
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.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ reverse a string in java
Reverse a String in Java - Scaler Topics
March 14, 2024 - Reversing a string in Java by extracting each character and adding it in front of the existing string is a straightforward approach. This method iterates through the input string, takes each character, and places it at the beginning of a new string.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ lang โ€บ String.html
String (Java Platform SE 8 )
April 21, 2026 - 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.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ calculate-string-length
Calculate String Length Online
Upside Down Text Letter Randomizer NTLM Hash Generator Password Generator Random Words Generator Text Minifier Word Repeater String Builder Intelligent Message Filter Word Replacer Reverse String Text Reverser HTML Encode HTML Decode Base32 Encode Base32 Decode Base58 Encode Base58 Decode Base64 Encode Base64 Decode URL Encode URL Decode String to Hex Converter Hex to String Converter String to Binary Converter Binary to String Converter Case Converter Delimited Text Extractor Remove Punctuation Remove Accents Remove Duplicate Lines Remove Empty Lines Remove Line Breaks Remove Extra Spaces Remove Whitespace Remove Lines Containing Sort Text Lines Text to ROT13 ROT13 to Text Calculate String Length Text Flipper Text Replacer
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ a comprehensive guide to reversing a string in java
Reversing a String in Java: A complete guide | Great Learning
September 3, 2024 - Quite simply, reversing a string means transposing its characters so that the last character becomes the first, the second-last becomes the second, and so on, until the initial first character becomes the last.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_ref_string.asp
Java String Reference
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
๐ŸŒ
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.
๐ŸŒ
Careers360
careers360.com โ€บ home โ€บ online courses & certifications โ€บ articles
How to Reverse a String in Java: A Comprehensive Guide
May 21, 2025 - Top Java Bootcamp Courses To Pursue Right Now! ... Let us start with a basic yet effective method, the CharAt approach. This method allows you to reverse a string in Java by extracting characters one by one and appending them in reverse order.