AllInfoHub Logo

AllInfoHub – MCQ Practice

Collections Framework – Multiple Choice Questions (MCQs)

  1. 37. What is the average time complexity of getting a value by key in a `TreeMap`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)
  2. 38. Which collection class provides thread-safe operations?

    • A. ArrayList
    • B. HashSet
    • C. HashMap
    • D. Vector
  3. 39. Which collection class is a thread-safe alternative to `ArrayList`?

    • A. LinkedList
    • B. HashSet
    • C. Vector
    • D. Collections.synchronizedList(new ArrayList<>())
  4. 40. Which collection class is a thread-safe alternative to `HashMap`?

    • A. TreeMap
    • B. Hashtable
    • C. LinkedHashMap
    • D. Collections.synchronizedMap(new HashMap<>())
  5. 41. What is the difference between `Vector` and `ArrayList`?

    • A. `Vector` is not synchronized
    • B. `ArrayList` is synchronized
    • C. `Vector` is synchronized
    • D. `ArrayList` is not
  6. 42. What is the difference between `Hashtable` and `HashMap`?

    • A. `Hashtable` allows null keys and values
    • B. `HashMap` does not
    • C. `HashMap` allows one null key and multiple null values
    • D. `Hashtable` does not allow null keys or values
  7. 43. Which interface represents a collection that supports removal of elements while iterating?

    • A. Collection
    • B. List
    • C. Iterator
    • D. ListIterator
  8. 44. What is the purpose of the `remove()` method of the `Iterator` interface?

    • A. To remove all elements from the collection
    • B. To remove the current element from the collection
    • C. To remove the first element of the collection
    • D. To remove the last element of the collection
  9. 45. What happens if you try to modify a collection while iterating over it using a standard `for-each` loop?

    • A. A `ConcurrentModificationException` is thrown
    • B. The modification is ignored
    • C. The loop terminates silently
    • D. The behavior is undefined
  10. 46. Which interface represents a double-ended queue?

    • A. Queue
    • B. Deque
    • C. Stack
    • D. List
  11. 47. Which class implements the `Deque` interface?

    • A. ArrayList
    • B. HashSet
    • C. LinkedList
    • D. TreeMap
  12. 48. Which class provides a Last-In-First-Out (LIFO) stack implementation?

    • A. ArrayList
    • B. LinkedList
    • C. Stack
    • D. HashSet