Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
import java.util.concurrent.*;

public class CopyOnWriteListTest {
    public static void main(String... l) {
        CopyOnWriteArrayList list = new CopyOnWriteArrayList();
        list.add("Java");
        list.add("Merit");
        Iterator i = list.iterator();
        while (i.hasNext()) {
            i.next(); // LINE A
            list.add("Campus"); // LINE B
        }
        Iterator i2 = list.iterator();
        while (i2.hasNext()) {
            System.out.println(i2.next());
            i2.remove(); // LINE C
        }
    }
}


Java
Merit
Campus
Java
Merit
Campus
Campus
throws Exception at LINE A
throws Exception at LINE B
throws Exception at LINE C

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App