Loading

Q1.

Which of the following statements about LinkedList in Java is TRUE?

A. LinkedList is implemented using arrays.

B. LinkedList maintains insertion order.

C. LinkedList does not allow null elements.

D. LinkedList is faster than ArrayList for random access.

Q2.

What is the time complexity of inserting an element at the beginning of a LinkedList?

A. O(1)

B. O(n)

C. O(log n)

D. O(n²)

Q3.

Which interfaces are implemented by LinkedList?

A. List only

B. List and Set

C. List, Deque, and Queue

D. Collection only

Q4.

What will the following code output?


LinkedList<String> list = new LinkedList<>();

list.add("Java");

list.addFirst("C++");

list.addLast("Python");

System.out.println(list);

A. [Java, C++, Python]

B. [C++, Java, Python]

C. [Java, Python, C++]

D. Compilation error

Q5.

 What exception does LinkedList throw when accessing an invalid index?

A. NullPointerException

B. IllegalStateException

C. IndexOutOfBoundsException

D. ArrayIndexOutOfBoundsException