What is the result?

Given:
List<String> list1 = new ArrayList<>(); list1.add("A"); list1.add("B");
List list2 = List.copyOf(list1); list2.add("C");
List<List<String>> list3 = List.of(list1, list2); System.out.println(list3);
What is the result?
A. [[A, B],[A, B]]
B. An exception is thrown at run time.
C. [[A, B], [A, B, C]]
D. [[A, B, C], [A, B, C]]

Download Printable PDF. VALID exam to help you PASS.

One thought on “What is the result?

  1. B)

    The List.of and List.copyOf static factory methods provide a convenient way to create unmodifiable lists. The List instances created by these methods have the following characteristics:

    They are unmodifiable. Elements cannot be added, removed, or replaced. Calling any mutator method on the List will always cause UnsupportedOperationException to be thrown. However, if the contained elements are themselves mutable, this may cause the List’s contents to appear to change.

    https://docs.oracle.com/javase/10/docs/api/java/util/List.html

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.