Find the output

What is the output of the following java code?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class x 
{
    public static void main(String[] args)    {
        ArrayList<Integer> n = new ArrayList<Integer>();
        n.add(3);
        n.add(1);
        n.add(2,4);
        n.add(1);
        n.add(5);
        n.remove(3);
        n.add(9);
        n.add(2);
        n.remove((Integer) 4);
        System.out.println(n);
    }
}

[3, 1, 5, 9, 2, 6] None of these [3, 1, 4, 5, 2, 6] [3, 1, 4, 1, 5, 9, 2, 6] Runtime Error [1, 1, 5, 9, 2, 6] [1, 4, 1, 5, 2, 6] Compile Time Error

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Alex Li
Apr 23, 2015

Note that ArrayList has never been imported, so the code will not compile.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...