OCA Java SE 8 Core Java APIs - OCA Mock Question Core Java APIs 3-5








Question

What is the result of the following?

     1: List<Integer> list = Arrays.asList(10, 4, -1, 5); 
     2: Collections.sort(list); 
     3: Integer array[] = list.toArray(new Integer[4]); 
     4: System.out.println(array[0]); 
  1. -1
  2. 10
  3. Compiler error on line 1.
  4. Compiler error on line 2.
  5. Compiler error on line 3.
  6. An exception is thrown.




Answer



A.

Note

Line 1 creates a fixed size array of size 4.

Line 2 sorts it.

Line 3 converts it back to an array.

The brackets aren't in the traditional place, but they are still legal.

Line 4 prints the first element, which is now -1.