Which three initialization statements are valid? (Choose three.)
Which three initialization statements are valid? (Choose three.)
List.of, Map.of, and Set.of are all valid methods for creating unmodifiable collections of their respective types. Arrays.of and ArrayList.of are not valid methods. List.of does not allow null elements, and Set.of does not allow duplicate elements. Therefore, the valid initialization statements here are: List.of(“UK”, “US”); Map.of(“UK”, 1, “US”, 2); and Set.of(“UK”, “US”).
Tested: BDG.
BDG is correct
Not tested but a bit obvious
BDG. C throws a NullPointerException and F throws a IllegalArgumentException
B. var loc = List.of("UK", "US"); D. var loc = Map.of("UK", 1, "US", 2); G. var loc = Set.of("UK", "US"); List.of, Map.of, and Set.of are all valid methods for creating unmodifiable collections of their respective types. The other options are invalid because: A. Arrays.of is not a valid method. C. List.of does not allow null elements. E. ArrayList.of is not a valid method. F. Set.of does not allow duplicate elements.