StringBuffer reverse() Method in Java

Rumman Ansari   Software Engineer   2019-03-30   6125 Share
☰ Table of Contents

Table of Content:


You can reverse the characters within a StringBuffer object using reverse( ), shown here:

Syntax

StringBuffer reverse( )

This method returns the reversed object on which it was called. The following program demonstrates reverse( ):

Program

// Using reverse() to reverse a StringBuffer.
class ReverseDemo {
public static void main(String args[]) {
	StringBuffer strng = new StringBuffer("abcdef");
	System.out.println(strng);
	strng.reverse();
	System.out.println(strng);
	}
}

Output

abcdef
fedcba
Press any key to continue . . .