Java OCA OCP Practice Question 1362

Question

What is the result of the following?

import java.util.*; 

public class Main { 
   public static void main(String[] args) { 
      String[] array = {"A", "B", "Art"}; 
      List<String> v = Arrays.asList(array); 
      v.remove(2); // w  w w.j a  v a2  s.  com
      System.out.println(v); 
   } 
} 
? 
  • A. [A, B]
  • B. [A, B, Art]
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


D.

Note

When converting an array to a List, Java uses a fixed-sized backed list.

The list uses an array in the implementation.

While changing elements to new values is allowed, adding and removing elements is not.




PreviousNext

Related