Menu
Topics Index
...
`

StringBufferDemo5 - Java Example Program


StringBufferDemo5
class StringBufferDemo5
{
    public static void main(String args[])
    {
    
        StringBuffer sb = new StringBuffer("Merit Campus "); // LINE A
        sb.insert(sb.length(), "Your Online Java School. "); // LINE B
        System.out.println(sb);
    }
}
OUTPUT

Merit Campus Your Online Java School.

DESCRIPTION

Firstly, "Merit Campus " is taken into the StringBuffer. At the end of the StringBuffer, String "Your Online Java School. " is inserted. Finally the StringBuffer is printed.

THINGS TO TRY
  • Place the below code after LINE B in the above program and check the output.
    CharSequence ch = "Don't Just Learn Java, Do Java";
    sb.insert(sb.length(), ch);
    System.out.println(sb);
    Output for the above code :
    Merit Campus Your Online Java School. Don't Just Learn Java, Do Java
RESET_CODE
  • Place the below code after LINE B in the above program and check the output.
    sb.insert(sb.length(), " Do Java with ");
    sb.insert(sb.length(), 600);
    System.out.print(sb + "+ practise programs.");
    Output for the above code :
    Merit Campus Your Online Java School. Do Java with 600+ practise programs.

© meritcampus 2019

All Rights Reserved.

Open In App