Return to site
JAVA CERTIFICATION QUESTION: Manipulating Java lists—and views of lists
JAVA CERTIFICATION QUESTION: Manipulating Java lists—and views of lists
=>Is a list unmodifiable? Is it immutable? What about the views of the list?
·
Given the following code fragment
String[] arr = new String[] {"A1", "A2"}; List<String> ls = new ArrayList<>(); ls.add("L1");ls.add("L2"); List<String> la = Arrays.asList(arr); List<String> lf = List.of(arr); List<String> lc = List.copyOf(ls); List<String> lu = Collections.unmodifiableList(ls); arr[1]="A3"; ls.set(1, "L3"); // line n1 System.out.println("la=" + la); System.out.println("lf=" + lf); System.out.println("lc=" + lc); System.out.println("lu=" + lu);
Which statements are correct? Choose three.
- A. The output contains la=[A1, A2]
- B. The output contains lf=[A1, A2]
- C. The output contains lc=[L1, L3]
- D. The output contains lu=[L1, L3]
- E. If you add the following at line n1, the output will contain lf=[A1, A3]: lf.set(1, "A3");
- F. If you add the following at line n1, the output will contain la=[A1, A3]: la.set(1, "A3");
#java #certificationquestion #ocp
·ꓞ puɐ ʻꓷ ʻꓭ suoᴉʇdo ǝɹɐ sɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ