VOOZH about

URL: https://www.geeksforgeeks.org/java/stringbuilder-reverse-in-java-with-examples/

⇱ StringBuilder reverse() in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

StringBuilder reverse() in Java with Examples

Last Updated : 22 Jan, 2026

The reverse method of the StringBuilder class is used to reverse the sequence of characters in a StringBuilder object. The original sequence is modified in-place, making it useful for dynamic string manipulation, palindrome checks, and efficient character sequence operations without creating new string objects.


Output
Original String: Hello
Reversed String: olleH

Explanation: The original StringBuilder "Hello" is reversed in-place using reverse(), producing "olleH".

Syntax

public StringBuilder reverse()

  • Returns: A StringBuilder object containing the reversed character sequence.
  • Example: This code demonstrates reversing a StringBuilder using the reverse() method in Java.

Example: Reversing Words Using StringBuilder


Output
String = WelcomeGeeks
Reverse String = skeeGemocleW

Explanation: The program converts the given string into a StringBuilder object so it can be modified. The reverse() method reverses all characters in the sentence, and the result is printed to the console.

Related Topics

Comment