In this example, let us see how to reverse the content of the StringBuffer with reverse method of java StringBuffer class.
Source Code
package com.beginner.examples;
public class StringBufferReverse {
public static void main(String[] args) {
StringBuffer stringBuffer = new StringBuffer("Hello World");
System.out.println("Before reversing , stringBuffer is : " + stringBuffer);
/*
* To reverse the StringBuffer use reverse() method of Java StringBuffer.
*/
stringBuffer.reverse();
System.out.println("After reversing , stringBuffer is : " + stringBuffer);
}
}
Output:
Before reversing , stringBuffer is : Hello World
After reversing , stringBuffer is : dlroW olleH