LinkedList<Integer> link_list = new LinkedList<>();
link_list.add(3);
link_list.add(4);
link_list.add(2, 1);
System.out.println(link_list);
link_list.add(2, 0);
System.out.print(link_list); 

Output of the above program
(A) [3, 4, 1]
[3, 4, 0]
(B) [3, 4, 1]
[3, 4, 0, 1]
(C) [3, 4, 1]
[3, 4, 1, 0]
(D) None of the mentioned


Answer: (B)

Explanation: add(element): appends the element to the end of the list.
add(index, element): appends the element at the \’index\’ position.

Quiz of this Question


  • Last Updated : 20 Nov, 2018

Share your thoughts in the comments