by @codeexamples

How to reverse a string using StringBuffer class in Java

Home » java » How to reverse a string using StringBuffer class in Java

Java offers us a StringBuffer class by chaining it with reverse() method and toString() method we can reverse a string.

Here is an example:

String string="oops";

String reverse = new StringBuffer(string).reverse().toString();

System.out.println(reverse); // it prints reverse string

Output:

spoo