Menu
Topics Index
...
`


Strings > StringBuffer >
Siva Nookala - 01 Apr 2016
We can reverse the characters in the StringBuffer using reverse.

The reverse method reverses the StringBuffer object on which it is called.
StringBuffer reverse()

The following example program demonstrates reverse():
StringBufferreverse Demo
class StringReverseExample
{
    public static void main(String arg[])
    {
        StringBuffer firstWord = new StringBuffer("Hello World");
        System.out.println(firstWord);
        firstWord.reverse();
        System.out.println(firstWord);    
    }
}
OUTPUT

Hello World
dlroW olleH

DESCRIPTION

This program shows how to reverse the contents within StringBuffer object firstWord. The first output line Hello World is just the display of the contents of firstWord. Then reverse() is used to reverse the contents of firstWord, so the second output dlroW olleH is the result of it.

THINGS TO TRY
  • Try this program for strings like "madam", "window". Show that the above mentioned strings are palindromes.

Dependent Topics : Additional StringBuffer Methods In Java  BufferedReader In Java  Java StringBuffer  

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.