Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class LoopTest {
    public static void main(String... l) {
        List<String> li = new ArrayList<String>();
        li.add("Hai");
        li.add("Hello");
        ListIterator i = li.listIterator();
        while (i.hasNext()) {
            i.add("Hi"); // Line 1
                }
        System.out.println(li);
    }
}


[Hi, Hai, Hi, Hello]
[Hai, Hello]
[Hai, Hello, Hi, Hi]
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: List Iterator 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