![]() |
VOOZH | about |
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.
Original String: Hello Reversed String: olleH
Explanation: The original StringBuilder "Hello" is reversed in-place using reverse(), producing "olleH".
public StringBuilder reverse()
Example: Reversing Words Using StringBuilder
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.