Menu
Question Index
...

What will be the output of the following program?

public class MovieCapacity {
    public static void main(String[] args) {
        String[] Movies = {"DHOOM-3","KRISH","CHENNAI EXPRESS"};
        StringBuffer names[] = new StringBuffer[3];
        for (int i = 0; i < Movies.length; i++) {
            names[i] = new StringBuffer(Movies[i]);
        }
        print(names, 5);
        print(names, 95);
    }
    private static void print(StringBuffer[] names, int j) {
        for (StringBuffer name : names) {
            System.out.print(name + " capacity- " + name.capacity() + " ");
            name.ensureCapacity(j);
        }
        System.out.println();
    }
}


DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31
DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31
DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31
DHOOM-3 capacity- 95 KRISH capacity- 95 CHENNAI EXPRESS capacity- 95
DHOOM-3 capacity- 5 KRISH capacity- 5 CHENNAI EXPRESS capacity- 5
DHOOM-3 capacity- 95 KRISH capacity- 95 CHENNAI EXPRESS capacity- 95
DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31
DHOOM-3 capacity- 118 KRISH capacity- 116 CHENNAI EXPRESS capacity- 126
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