Java LinkedList

Here are 10 essential multiple-choice questions on Java LinkedList, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

Which package contains the LinkedList class in Java?

  • java.linked


  • java.util

  • java.list

  • java.collection

Question 2

Which data structure does Java's LinkedList internally use?

  • Dynamic Array

  • Doubly Linked List

  • Circular Linked List


  • Single Linked List

Question 3

What will be the output of the following code?

Java
import java.util.*; public class Test {     public static void main(String[] args) {         LinkedList<Integer> list = new LinkedList<>();         list.add(10);         list.addFirst(5);         list.addLast(15);         System.out.println(list);     } } 


  • [10, 5, 15]

  • [5, 10, 15]


  • [5, 15, 10]

  • [10, 15, 5]

Question 4

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

  • O(1)

  • O(n)


  • O(log n)


  • O(n²)


Question 5

What will happen if you try to access an element at an invalid index using get(int index)?


  • It returns null

  • It returns 0

  • It throws IndexOutOfBoundsException

  • It removes the last element

Question 6

Which of the following statements about LinkedList and ArrayList is true?

  • LinkedList provides faster random access than ArrayList


  • LinkedList consumes more memory than ArrayList

  • ArrayList consumes more memory than LinkedList

  • ArrayList is always faster than LinkedList

Question 7

What will be the result of the following code?

Java
import java.util.*; public class Test {     public static void main(String[] args) {         LinkedList<String> list = new LinkedList<>();         list.add("A");         list.add("B");         list.add("C");         list.remove("B");         System.out.println(list);     } } 


  • [A, B, C]


  • [A, C]

  • [B, C]

  • [C, B, A]


Question 8

How does LinkedList differ from ArrayList when searching for an element?

  • LinkedList has O(1) search time, while ArrayList has O(n)

  • ArrayList has O(1) search time, while LinkedList has O(n)


  • Both have O(n) search time


  • LinkedList has O(log n) search time

Question 9

What happens when pollFirst() is called on an empty LinkedList?


  • It returns null

  • It throws NoSuchElementException

  • It removes the last element

  • It removes the first element

Question 10

Which method retrieves, but does not remove, the last element of a LinkedList?


  • peekLast()


  • lastElement()

  • getLast()

  • rear()

There are 10 questions to complete.

Take a part in the ongoing discussion