Menu
Question Index
...

What will be the output of the following program?

public class StringBufferConStructors {
    public static void main(String[] args) {
        StringBuffer stringBuffer1 = new StringBuffer(10);
        StringBuffer stringBuffer2 = new StringBuffer("MERIT CAMPUS");
        StringBuffer stringBuffer3 = new StringBuffer(1);
        StringBuffer stringBuffer4 = new StringBuffer('J');
        System.out.println(stringBuffer1.capacity() + "-" + stringBuffer2 + "-" + stringBuffer3.capacity() + "-" + stringBuffer4.toString());
    }
}


-MERIT CAMPUS--
10-MERIT CAMPUS-1-
10-MERIT CAMPUS-1-J
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java StringBuffer length() And capacity() Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App