StringBuilder reverse does not produce a new StringBuilder instance. It causes the underlying characters of the current StringBuilder to be reversed. So,

String a = s.reverse().toString(); 
String b = s.toString();

The second s.toString() is operating on the reversed StringBuilder.

you have to do

String original = s.toString(); 
String reversed = s.reverse().toString();
return original.equals(reversed);
Answer from Thiyagu on Stack Overflow
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
April 21, 2026 - public StringBuilder reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.
🌐
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()); } }
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_reverse.htm
Java StringBuilder reverse() Method
The Java StringBuilder reverse() method is used to reverse the characters of a StringBuilder object. It replaces the sequence of characters in reverse order. The method is a static method with predefined logic for reversing a string in Java.
Find elsewhere
🌐
Moon Technolabs
moontechnolabs.com › qanda › stringbuilder-in-java
How Do You Reverse a String Using StringBuilder in Java?
June 6, 2025 - Reversing a string using StringBuilder in Java is simple and efficient because StringBuilder provides a built-in reverse() method that allows you to reverse the string in a single step.
🌐
Javainsimpleway
javainsimpleway.com › tag › stringbuilder-reverse-method-in-java
StringBuilder reverse() method in java | Javainsimpleway
importance of stringbuilder class String builder in java with example stringbuilder append() in java stringbuilder in java StringBuilder length() method in java StringBuilder replace() method in java StringBuilder reverse() method in java · StringBuilder is very similar to StringBuffer except for one important difference which is not synchronized.
🌐
GeeksforGeeks
geeksforgeeks.org › java › reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
Explanation: StringBuilder objects are mutable, and their reverse() method reverses the content in-place, which is faster than manual looping. We can use character array to reverse a string.
Published   May 12, 2026
🌐
Quora
quora.com › What-is-inbuilt-function-used-for-a-reversal-of-string-in-Java
What is inbuilt function used for a reversal of string in Java? - Quora
Answer (1 of 3): The most easiest way is to using StringBuffer’s inbuilt reverse() method. This works like below: String string = “HelloWorld”; StringBuffer buffer = new StringBuffer(string); String reverse = buffer.reverse().toString(); System.out.printf(“Reverse String: “+reverse); ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-stringbuilder-reverse
Java StringBuilder reverse()
It returns a StringBuilder instance that contains the reverse of the given sequence. public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Tomato"); System.out.println("Given String: "+sb); //reverse the String "Tomato" sb.reverse(); //print ...
🌐
Quora
quora.com › How-can-a-string-be-reversed-in-Java
How can a string be reversed in Java? - Quora
Answer (1 of 3): // Sample program: import java.lang.*; // java.lang.System && java.lang.StringBuilder class StringReverse { public static void main(String[] args) { String network_search = "lssnepo nasegurum"; System.out.println( "My network_search: " + new StringBuilder( network_search )...
🌐
TutorialKart
tutorialkart.com › java › java-stringbuilder-reverse
Java StringBuilder.reverse() - Syntax & Examples
January 24, 2021 - public class Example { public static void main(String[] args) { StringBuilder stringBuilder = new StringBuilder(); System.out.println("Before reversing : " + stringBuilder.toString()); stringBuilder.reverse(); System.out.println("After reversing : " + stringBuilder.toString()); } } ... In this Java Tutorial, we have learnt the syntax of Java StringBuilder.reverse() function, and also learnt how to use this function with the help of examples.
🌐
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

🌐
FavTutor
favtutor.com › blogs › reverse-string-java
Reverse a String in Java (with Examples)
September 28, 2024 - Using a for loop, iterate through the array of words in reverse order. Add a space after each word in the StringBuilder. Finally, use the toString() method to convert the StringBuilder to a string.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuffer_reverse.htm
Java StringBuffer reverse() Method
In the following example, we are creating an object of the StringBuffer class with the value "malayalam". Then, using the reverse() method we reverse the string.
🌐
LeetCode
leetcode.com › problems › reverse-words-in-a-string
Reverse Words in a String - LeetCode
Can you solve this real interview question? Reverse Words in a String - Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order ...