Java LinkedList

Last Updated :
Discuss
Comments

Question 1

Which data structure does Java's LinkedList internally use?

  • A

    Dynamic Array

  • B

    Doubly Linked List

  • C

    Circular Linked List


  • D

    Single Linked List

Question 2

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);
    }
}


  • A

    [10, 5, 15]

  • B

    [5, 10, 15]


  • C

    [5, 15, 10]

  • D

    [10, 15, 5]

Question 3

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²)


Question 4

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


  • A

    It returns null

  • B

    It returns 0

  • C

    It throws IndexOutOfBoundsException

  • D

    It removes the last element

Question 5

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

  • A

    LinkedList provides faster random access than ArrayList


  • B

    LinkedList consumes more memory than ArrayList

  • C

    ArrayList consumes more memory than LinkedList

  • D

    ArrayList is always faster than LinkedList

Question 6

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


  • A

    It returns null

  • B

    It throws NoSuchElementException

  • C

    It removes the last element

  • D

    It removes the first element

Question 7

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


  • A

    peekLast()


  • B

    lastElement()

  • C

    getLast()

  • D

    rear()

There are 7 questions to complete.

Take a part in the ongoing discussion