Multiple choice technology programming languages

Which is simplest code snippet you will add in the below main function to set the name attribute of 50th in the ItemList to “Done”? import java.util.ArrayList; import java.util.List; class Item { public int code; public String name; public Item(String name) { this.name = name; } } public class Main { public static void main(String args[]) { List itemList = new ArrayList(); for (int i = 0; i < 50; i++) { Item im = new Item("Test"); itemList.add(im); } //Code to change name of the 50th object to “Done” } }

  1. im.name = "Done";

  2. Item otherObject = new Item(“Done”); itemList.set(49, otherObject);

  3. ((Item)itemList.get(49)).name = “Done”;

  4. None of above is correct as they are not changing 50th element.

Reveal answer Fill a bubble to check yourself
A Correct answer