Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class DeleteElementsFromList {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(3); list.add(10); list.add(1); list.add(2);
        list.add(7); list.add(0); list.add(5);
        print(list.remove(2));
        print(list.remove((Integer) 7));
        print(list.remove(2));
        print(list.remove(new Integer(7)));
        print(list.remove(0));
        print(list.remove(new Integer(10)));
        print(list.size());
    }

    public static void print(int value)
    {
        System.out.print(value + " ");
    }

    public static void print(boolean value)
    {
        System.out.print(value ? "X " : "Y ");
    }
}


X 1 Y 2 2 X 3
1 X 2 Y 3 X 2
X X X Y X X X
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App