Which collection class(es) allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? (Choose all that apply.)

  1. java.util.HashSet

  2. java.util.LinkedHashSet

  3. java.util.List

  4. java.util.ArrayList

  5. java.util.Vector

  6. java.util.PriorityQueue


Correct Option: D

AI Explanation

To answer this question, you need to understand the characteristics of different collection classes in Java. Let's go through each option to understand which class(es) allow you to grow or shrink its size and provide indexed access to its elements, without being synchronized:

Option A) java.util.HashSet - This class does not provide indexed access to its elements.

Option B) java.util.LinkedHashSet - This class does not provide indexed access to its elements.

Option C) java.util.List - The List interface allows you to grow or shrink its size and provides indexed access to its elements. However, this option does not specify a specific implementation of the List interface.

Option D) java.util.ArrayList - This class allows you to grow or shrink its size and provides indexed access to its elements. The methods of ArrayList are not synchronized.

Option E) java.util.Vector - This class allows you to grow or shrink its size and provides indexed access to its elements. However, the methods of Vector are synchronized, so it does not meet the requirement of not having synchronized methods.

Option F) java.util.PriorityQueue - This class does not provide indexed access to its elements.

The correct answer is D) java.util.ArrayList. This class allows you to grow or shrink its size and provides indexed access to its elements, without the methods being synchronized.

Find more quizzes: