Menu
Question Index
...

What will be the output of the following program?

public class StringBufferDemo {
    public static void main(String[] args) {
        StringBuffer firstBuffer = new StringBuffer("Merit Campus");
        System.out.println("First Buffer = " + firstBuffer);
        System.out.println("Old Capacity = " + firstBuffer.capacity());
        firstBuffer.ensureCapacity(27);
        System.out.println("New Capacity = " + firstBuffer.capacity());
    }
}


First Buffer = Merit Campus
Old Capacity = 16
New Capacity = 27
First Buffer = Merit Campus
Old Capacity = 28
New Capacity = 27
First Buffer = Merit Campus
Old Capacity = 28
New Capacity = 28
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java StringBuffer ensureCapacity() 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