QuizzesCollections Utility Methods — Concept Check
intermediate
java

Collections Utility Methods — Concept Check

Questions on Collections Utility Methods. Master the Collections utility class — sorting, searching, shuffling, frequency, min/max, unmodifiable and synchronized wrappers.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Collections Utility Methods — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You have a list of integers that needs to be sorted in descending order. Which method should you use?

    • ACollections.reverse(list)
    • BCollections.shuffle(list)
    • CCollections.sort(list, Collections.reverseOrder())
    • DCollections.sort(list)
  2. 2.A list of strings is passed to Collections.binarySearch without prior sorting. What is the likely outcome?

    • ACorrect index of the element
    • BAlways returns -1
    • CUnpredictable results
    • DThrows an exception
  3. 3.You need to ensure a list cannot be modified. Which method should you use?

    • AList.of(list)
    • BCollections.synchronizedList(list)
    • CCollections.unmodifiableList(list)
    • DCollections.nCopies(1, list)
  4. 4.Given a list, you want to randomly rearrange its elements. Which method is appropriate?

    • ACollections.rotate(list, 1)
    • BCollections.reverse(list)
    • CCollections.sort(list)
    • DCollections.shuffle(list)
  5. 5.A list of words is given, and you need to find the most frequently occurring word. Which method helps?

    • ACollections.frequency(list, word)
    • BCollections.max(list)
    • CCollections.sort(list)
    • DCollections.min(list)
  6. 6.You have two lists and want to check if they share any elements. Which method should you use?

    • ACollections.frequency(list1, list2)
    • BCollections.disjoint(list1, list2)
    • CCollections.synchronizedList(list1)
    • DCollections.addAll(list1, list2)
  7. 7.In a multithreaded environment, which method ensures thread-safe operations on a list?

    • ACollections.unmodifiableList(list)
    • BCollections.shuffle(list)
    • CCollections.rotate(list, 1)
    • DCollections.synchronizedList(list)
  8. 8.What happens if you try to add an element to a list created with List.of()?

    • AElement is added
    • BList resizes automatically
    • CThrows UnsupportedOperationException
    • DList is sorted after addition