Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
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].
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.
C is correct
C is correct, add method in list has two implementatios whit a element o with index and element
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.
Tested: C.
C is correct. There's no compilation error
B is correct Tested
did u test?
Correct answer is C