This post will discuss how to reverse a string using StringBuilder and StringBuffer in Java.

 
The following example demonstrates how to use the StringBuilder.reverse() method to reverse a string in Java efficiently.

Download  Run Code

Output:

The reversed string is thgileD eihceT

 
Alternatively, we can also use the StringBuffer.reverse() method. Using StringBuilder is suggested as it’s not synchronized and faster than StringBuffer.

Download  Run Code

That’s all about reversing a String using StringBuilder and StringBuffer in Java.