Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class BigBoss {

    public static void main(String a[]) {
        List<String> list = new ArrayList<String>();
        list.add("one");
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        System.out.println("Before list: " + list);
        Collections.fill(list, "one");
        list.add("five");
        System.out.println("After list: " + list);
        System.out.println("Frequency: " + Collections.frequency(list, "one"));
    }
}


Before list: [one, one, two, three, four]
After list: [one, one]
Frequency: 2
Before list: [one, one, two, three, four]
After list: [one, one, one, one, one, five]
Frequency: 5
Before list: [one, one, two, three, four]
After list: [two, three, four, five]
Frequency: 0
Before list: [one, one, two, three, four]
After list: [one, one, five]
Frequency: 2
Compilation Error or Runtime Error

Doubts

Problems

Topic: java.util.Arrays - Class Arrays In Collection Framework

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App