AllInfoHub Logo

AllInfoHub – MCQ Practice

Collections Framework – Multiple Choice Questions (MCQs)

  1. 25. How do you sort a `List` of objects using the natural ordering?

    • A. Using the `sort()` method of the `List` interface
    • B. Using `Collections.sort()` with the `List`
    • C. Using `Arrays.sort()` with the `List`
    • D. Using a for loop to manually sort
  2. 26. How do you sort a `List` of objects using a custom `Comparator`?

    • A. Using the `sort()` method of the `List` interface with the `Comparator`
    • B. Using `Collections.sort()` with the `List` and the `Comparator`
    • C. Using `Arrays.sort()` with the `List` and the `Comparator`
    • D. Using a for loop with custom comparison
  3. 27. Which class provides static methods for operating on collections?

    • A. Arrays
    • B. Collections
    • C. Objects
    • D. List
  4. 28. What is the purpose of the `Collections.sort()` method?

    • A. To reverse the order of elements in a collection
    • B. To shuffle the elements in a collection
    • C. To sort the elements in a collection
    • D. To search for an element in a collection
  5. 29. What is the purpose of the `Collections.shuffle()` method?

    • A. To sort the elements in a collection
    • B. To reverse the order of elements in a collection
    • C. To randomly permute the elements in a collection
    • D. To find the minimum element in a collection
  6. 30. What is the purpose of the `Collections.reverse()` method?

    • A. To sort the elements in a collection
    • B. To reverse the order of elements in a collection
    • C. To shuffle the elements in a collection
    • D. To find the maximum element in a collection
  7. 31. What is the purpose of the `Collections.binarySearch()` method?

    • A. To find the index of a specific element in a sorted list
    • B. To sort the elements in a list
    • C. To reverse the order of elements in a list
    • D. To shuffle the elements in a list
  8. 32. What is the time complexity of accessing an element by index in an `ArrayList`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)
  9. 33. What is the time complexity of accessing an element by index in a `LinkedList`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)
  10. 34. What is the average time complexity of searching for an element in a `HashSet`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)
  11. 35. What is the average time complexity of searching for an element in a `TreeSet`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)
  12. 36. What is the average time complexity of getting a value by key in a `HashMap`?

    • A. O(1)
    • B. O(n)
    • C. O(log n)
    • D. O(n log n)