Chapter 5Working with Arrays and Collections

  1. What is the output of the following?
    List<String> museums = new ArrayList<>(1);
    museums.add("Natural History");
    museums.add("Science");
    museums.add("Art");
    museums.remove(2);
    System.out.println(museums);
    
    1. [Natural History, Science]
    2. [Natural History, Art, Science]
    3. The code does not compile.
    4. The code compiles but throws an exception at runtime.
  2. How many of the following are legal declarations?
    []String lions = new String[];
    String[] tigers = new String[1] {"tiger"}; ...

Get OCP Oracle Certified Professional Java SE 17 Developer Practice Tests now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.