Reverse a string using StringBuilder and StringBuffer in Java

In this post, we will see how to reverse a string using StringBuilder and StringBuffer in Java.

 
Following example illustrates how to use StringBuilder.reverse() method to efficiently reverse a string in Java.

 

Download   Run Code

Output:

Reversed string is : thgileD eihceT

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

 

 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 


Leave a Reply

avatar
  Subscribe  
Notify of