Menu
Topics Index
...
`

StringBufferreverse Demo - Java Example Program


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.

© meritcampus 2019

All Rights Reserved.

Open In App