Menu
Question Index
...

What will be the output of the following program?

public class Offers {
    public static void main(String[] args) {
        StringBuffer s1 = new StringBuffer(5);
        System.out.print(s1.capacity() + " ");
        s1.ensureCapacity(8);
        System.out.print(s1.capacity() + " ");
        s1.ensureCapacity(30);
        System.out.print(s1.capacity() + " ");
        s1.setLength(s1.length() + 10);
        System.out.print(s1.length());
    }
}


5 8 30 15
5 12 30 10
0 8 30 10
Some other output
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