Home » Java programming language

Java StringBuffer reverse() method with Example

Java StringBuffer reverse() method: Here, we are going to learn about the reverse() method of StringBuffer class with its syntax and example.
Submitted by Preeti Jain, on June 29, 2019

StringBuffer Class reverse()

  • This method is available in package java.lang.StringBuffer.reverse().
  • This method is used to reverse the representation of the objects.
  • This method does not raise an exception during runtime.

Syntax:

    StringBuffer reverse(){
    }

Parameter(s):

We don't pass any object as a parameter in the method of the StringBuffer.

Return value:

The return type of this method is StringBuffer that means this method returns a reference to this object.

Java program to demonstrate example of reverse() method

import java.lang.StringBuffer;

public class StringBufferClass {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Java is a programming language");

        // use reverse() it will reverse the characters of the sb object.
        // Display result after reversing string sequence

        System.out.println("The result will be after reversing a string :" + sb.reverse());

        sb = new StringBuffer(123456);

        // use reverse() it will reverse the integers
        // Display result after inserting
        System.out.println("The result will be after reversing an string object :" + sb.reverse());
    }
}

Output

D:\Programs>javac StringBufferClass.java

D:\Programs>java StringBufferClass
The result will be after reversing a string :egaugnal gnimmargorp a si avaJ
The result will be after reversing an integer object :654321





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.