Modifying a Shopping List

Your shopping list is stored in an ArrayList and when printed gives you the following output:

Apple
Banana
Banana
Dumpling
You notice that you accidentally added Banana twice and you had meant to add Carrot after the first Banana. Assuming that your ArrayList is called list, which of the following commands will modify list so that printing it will produce:

Apple
Banana
Carrot
Dumpling

list.add("Carrot");


list.remove(2);


list.get(1);


list.set(2, "Carrot");



Answer :

Other Questions