AllInfoHub Logo

AllInfoHub – MCQ Practice

Collections Framework – Multiple Choice Questions (MCQs)

  1. 13. Which interface provides methods for accessing elements in a sequential manner?

    • A. List
    • B. Set
    • C. Iterator
    • D. Map
  2. 14. How do you iterate over the elements of a `Collection` using an `Iterator`?

    • A. Using a for-each loop
    • B. Using a while loop with `iterator.next()` and `iterator.hasNext()`
    • C. Using a traditional for loop with index
    • D. Using a do-while loop
  3. 15. What is the purpose of the `ListIterator` interface?

    • A. To iterate over `Set` elements
    • B. To iterate over `Map` entries
    • C. To iterate over `List` elements in both forward and backward directions
    • D. To iterate over `Queue` elements
  4. 16. What are generics in the Java Collections Framework?

    • A. A way to store multiple data types in a collection
    • B. A mechanism to provide type safety for collections
    • C. A way to improve the performance of collections
    • D. A feature for sorting collections
  5. 17. How do you declare an `ArrayList` that can only store `String` objects?

    • A. ArrayList strings = new ArrayList();
    • B. ArrayList<String> strings = new ArrayList<String>;
    • C. ArrayList[String] strings = new ArrayList[String];
    • D. List<String> strings = new List<String>();
  6. 18. What happens if you try to add an object of a different type to a generic collection?

    • A. A runtime exception is thrown
    • B. The object is automatically cast
    • C. A compile-time error occurs
    • D. The object is ignored
  7. 19. Which interface represents a collection that does not allow duplicate elements and provides methods for accessing elements in sorted order?

    • A. Set
    • B. SortedSet
    • C. NavigableSet
    • D. TreeSet
  8. 20. Which class implements the `SortedSet` interface?

    • A. HashSet
    • B. LinkedHashSet
    • C. TreeSet
    • D. ArrayList
  9. 21. Which interface represents a map that provides methods for accessing entries in sorted order of keys?

    • A. Map
    • B. SortedMap
    • C. NavigableMap
    • D. TreeMap
  10. 22. Which class implements the `SortedMap` interface?

    • A. HashMap
    • B. LinkedHashMap
    • C. TreeMap
    • D. ArrayList
  11. 23. What is the purpose of the `Comparable` interface?

    • A. To define a natural ordering for objects of a class
    • B. To provide custom comparison logic for sorting
    • C. To check if two objects are equal
    • D. To convert an object to a string
  12. 24. What is the purpose of the `Comparator` interface?

    • A. To define a natural ordering for objects of a class
    • B. To provide custom comparison logic for sorting
    • C. To check if two objects are equal
    • D. To convert an object to a string