Java Quiz Day 37

Last Updated :
Discuss
Comments

Question 1

Which of the following classes implement the List interface in Java?

  • A

    HashMap

  • B

    HashSet

  • C

    ArrayList

  • D

    TreeMap

Question 2

Which class among ArrayList, LinkedList, Vector, and Stack is synchronized (thread-safe)?

  • A

    ArrayList



  • B

    LinkedList

  • C

    Vector

  • D

    None of the above

Question 3

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

  • A

    O(1)


  • B

    O(n)

  • C

    O(log n)

  • D

    O(n log n)

Question 4

Which data structure is best for implementing a LIFO (Last In First Out) operation in Java?

  • A

    Queue


  • B

    Stack

  • C

    LinkedList

  • D

    PriorityQueue

Question 5

Which of the following allows fast insertions and deletions at both ends?

  • A

    ArrayList


  • B

    LinkedList

  • C

    Vector

  • D

    Stack

Question 6

What happens if you try to access an invalid index in an ArrayList?

  • A

    It returns null

  • B

    It throws ArrayIndexOutOfBoundsException

  • C

    It throws NullPointerException

  • D

    It throws IndexOutOfBoundsException

Question 7

How do you retrieve the top element from a Stack without removing it?

  • A

    pop()

  • B

    peek()

  • C

    top()

  • D

    get()

Question 8

Which collection should you prefer when frequent insertions and deletions are required in the middle of the list?

  • A

    ArrayList

  • B

    Vector

  • C

    LinkedList

  • D

    Stack

Question 9

Which collection type does NOT allow random access to its elements?

  • A

    ArrayList

  • B

    HashSet

  • C

    LinkedList

  • D

    TreeSet

Tags:

There are 9 questions to complete.

Take a part in the ongoing discussion