Menu
Question Index
...

What will be the output of following program?

public class MCPS {
    public static void main(String[] args) {
        StringBuffer buf = new StringBuffer("MeritCampus Programming Skills");
        buf.insert(12, "Learn");
        System.out.println(buf);
        MCPS sbd = new MCPS();
        System.out.print("Old Capacity = " + buf.capacity());
        buf.ensureCapacity(28);
        System.out.println(" New Capacity = " + buf.capacity());
        StringBuffer buff2 = new StringBuffer("Compile Online");
        System.out.print("Old Capacity = " + buff2.capacity());
        buff2.ensureCapacity(29);
        System.out.println(" New Capacity = " + buff2.capacity());
    }
}


MeritCampusLearn Programming Skills
Old Capacity = 46 New Capacity = 46
Old Capacity = 30 New Capacity = 30
MeritCampus LearnProgramming Skills
Old Capacity = 72 New Capacity = 100
Old Capacity = 30 New Capacity = 59
MeritCampus LearnProgramming Skills
Old Capacity = 72 New Capacity = 28
Old Capacity = 30 New Capacity = 29
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java StringBuffer insert() Method With Example

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App