StringBuffer reverse() Method in Java: Usage and Examples

Rumman Ansari   Software Engineer   2024-07-05 03:42:53   6066 Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

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 . . .