Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Capital {
    public static void main(String args[]) {
        List mylist = new ArrayList();
        int[] val = {15, 5565, 646, 233, 100};
        for (int element : val)
            mylist.add(new Integer(element));
        System.out.println(mylist);
        Iterator iterator = mylist.iterator();
        int i = mylist.size();
        while (iterator.hasNext()) {
            Integer element = (Integer) iterator.next();
            int value = element.intValue();
            i--;
            if ((value < 100) || mylist.get(i).equals(100))
                iterator.remove();
        }
        System.out.println(mylist);
    }
}


[15, 5565, 646, 233, 100]
[15, 5565, 646, 233]
[15, 5565, 646, 233, 100]
[5565, 646, 233]
[15, 5565, 646, 233, 100]
[]
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Iterator

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App