Java LinkedList

Last Updated :
Discuss
Comments

Question 1

Which data structure does Java's LinkedList internally use?

  • Dynamic Array

  • Doubly Linked List

  • Circular Linked List


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


  • [10, 5, 15]

  • [5, 10, 15]


  • [5, 15, 10]

  • [10, 15, 5]

Question 3

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 4

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 5

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 6

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 7

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


  • peekLast()


  • lastElement()

  • getLast()

  • rear()

There are 7 questions to complete.

Take a part in the ongoing discussion