Sail E0 Webinar
Question


What is the output of this program?


import java.util.*;
class Linkedlist {
public static void main(String args[]) {
LinkedList obj = new LinkedList();
obj.add("A");
obj.add("B");
obj.add("C");
obj.addFirst("D");
System.out.println(obj);
}
}
Options:
A .  [A, B, C]
B .  [D, B, C]
C .  [A, B, C, D]
D .  [D, A, B, C]
Answer: Option D

obj.addFirst("D") method is used to add 'D' to the start of a LinkedList object obj.
Output:
$ javac Linkedlist.java
$ java Linkedlist
[D, A, B, C]




Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers