1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 103


Given the code fragment:

What is the result?

Show Answer
Correct Answer: BC

In the provided code fragment, two ArrayLists are created and manipulated. For the first list, vegetables, 'Kale' is added first, followed by 'Lettuce' added at index 0, making the list ['Lettuce', 'Kale']. For the second list, fish, 'Salmon' is added first, followed by 'Seabass' added at index 0, making the list ['Seabass', 'Salmon']. When both lists are printed, the output will be [Lettuce, Kale] for the vegetables list and [Seabass, Salmon] for the fish list. Therefore, the correct result is [Lettuce, Kale] [Seabass, Salmon].

Discussion

8 comments
Sign in to comment
ObaltOption: C
Feb 8, 2023

Correct answer is C

StavokOption: B
Jul 19, 2023

B is correct Tested

Ashan_Ozlov
Sep 24, 2023

did u test?

[Removed]Option: C
Aug 30, 2023

C is correct. There's no compilation error

OmnisumemOption: C
Sep 25, 2023

Tested: C.

TheOneAboveAllOption: C
Oct 15, 2023

List vegetables = new ArrayList<> () ; vegetables.add ("Kale"); vegetables.add (0, "Lettuce"); System.out.println (vegetables); List fish = new ArrayList<> (); fish.add ("Salmon"); fish.add(0, "Seabass"); System.out.println(fish); Tested: C.

d7bb0b2Option: C
Dec 11, 2023

C is correct, add method in list has two implementatios whit a element o with index and element

f91f9beOption: C
Feb 5, 2024

C is correct

ASPushkinOption: C
Jun 13, 2024

AbstractCollection already overrides toString() to print the contents of its elements. So, just list.toString() prints the toString() of all its elements. This is true for all collections. public StringBuilder append​(Object obj) Appends the string representation of the Object argument.