Different ways to reverse String in java

There can be different ways to reverse the String. Here , we are mentioning few.

Let’s understand them with example.

1. We can reverse the string by using a for loop and method charAt.

Output:
Original String is Hello World!!
Reversed string is !!dlroW olleH

 

2. Using the StringBuffer class.

Output:
Original String is Hello World!!
Reversed string is !!dlroW olleH

 

3. Using the StringBuilder class.

Output:
Original String is Hello World!!
Reversed string is !!dlroW olleH
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
StringBuilder in java
I/O in java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...