Java Quiz Day 41

Last Updated :
Discuss
Comments

Question 1

Which method of the Iterator interface removes the last element returned by the iterator?

  • A

    delete()

  • B

    remove()

  • C

    clear()

  • D

    discard()

Question 2

What happens if you modify a collection directly while iterating over it using a normal Iterator?

  • A

    It updates automatically

  • B

    Throws ConcurrentModificationException

  • C

    Skips modified elements

  • D

    The iterator restarts

Question 3

Which iterator type allows iteration in both directions in Java?

  • A

    Iterator

  • B

    Enumeration

  • C

    CollectionIterator

  • D

    ListIterator

Question 4

If a class implements Comparable, which method must it override?

  • A

    equals(Object obj)

  • B

    compareTo(Object o)

  • C

    compare(Object o1, Object o2)

  • D

    hashCode()

Question 5

Which statement is TRUE about Comparator in Java?

  • A

    A comparator is used to define the natural ordering of objects.

  • B

    Comparator is implemented inside the class itself.

  • C

    Comparator can be used to define multiple sorting orders.

  • D

    Comparator can only sort Strings.

Question 6

In Comparable, the compareTo() method should return:

  • A

    Positive integer if current object is less than the specified object

  • B

    Zero if current object is greater

  • C

    Negative integer if current object is greater

  • D

    Positive integer if current object is greater than the specified object

Question 7

Which class from java.util.concurrent allows a thread to safely wait for another thread's completion?

  • A

    Semaphore

  • B

    CountDownLatch

  • C

    CyclicBarrier

  • D

    All of the above

Question 8

Which concurrent collection is best suited for a producer-consumer scenario?

  • A

    CopyOnWriteArrayList

  • B

    ConcurrentHashMap

  • C

    LinkedBlockingQueue

  • D

    ConcurrentSkipListMap

Question 9

Which concurrent collection maintains elements in a sorted order?


  • A

    ConcurrentHashMap

  • B

    CopyOnWriteArrayList

  • C

    ConcurrentSkipListSet

  • D

    ConcurrentLinkedQueue

Question 10

Which concurrent collection is an unbounded thread-safe queue based on linked nodes that orders elements according to FIFO (First-In-First-Out)?

  • A

    ConcurrentLinkedQueue

  • B

    LinkedBlockingQueue

  • C

    PriorityBlockingQueue

  • D

    ArrayBlockingQueue

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion