Menu
Topics Index
...
`

StringBuffer


If you need explanation Read this topic

If you need Answer Take test on this topic

StringBuffer
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());
    }
}

A. MeritCampusLearn Programming Skills
Old Capacity = 46 New Capacity = 46
Old Capacity = 30 New Capacity = 30
B. MeritCampus LearnProgramming Skills
Old Capacity = 72 New Capacity = 100
Old Capacity = 30 New Capacity = 59
C. MeritCampus LearnProgramming Skills
Old Capacity = 72 New Capacity = 28
Old Capacity = 30 New Capacity = 29
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java StringBuffer insert() Method With Example

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

C

Posted by Datta Sai Krishna    2014-07-25 09:39:12


c

Posted by Surendra Rathor    2014-07-25 09:43:16


D because the old capacity should be equal to 28 initially

Posted by Sahithi Boggarapu    2014-07-25 09:46:51


ans c,
1st old capacity total char * 2 including null gives 72
1
thn ensurcapacity printd.
compile online ve 15 char including null so 30
finaly ensurcapacity printd

Posted by Anand Kumar    2014-07-25 09:55:31


c

Posted by Ria Gupta    2014-07-25 10:11:10


c

Posted by Zeg Abder    2014-07-25 10:45:21


c

Posted by Manojkumar Kothagulla    2014-07-26 14:53:18


No winner for this dose. Correct option is 'D' i.e
"MeritCampus LearnProgramming Skills
Old Capacity = 46 New Capacity = 46
Old Capacity = 30 New Capacity = 30".

For more details about Ensurecapacity go to -

http://java.meritcampus.com/t/255/Ensurecapacity

Posted by Merit Campus    2014-07-28 06:54:37


© meritcampus 2019

All Rights Reserved.

Open In App