StringBuffer reverse() Method in Java: Usage and Examples
☰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 . . .