Which collection class allows you to grow or shrink?
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
- java.util.LinkedHashSet
- java.util.HashSet
- java.util.ArrayList
- java.util.HashSet
Answer C. java.util.Arraylist
The java.util.Arraylist collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized.
Solution
The answer to the question- Which collection class allows you to grow or shrink? is java.util.Arraylist. You can increase or decrease the size of your collection using any of the collection classes. The elements of an array list have an index. Synchronized methods are typically absent from the more recent collection classes. Vector is a slower version of ArrayList that has synchronized methods and is an older implementation of the functionality of ArrayList.
The Java collections framework’s LinkedHashSet class offers functionality of linked list and hashtable data structure. The Set interface is implemented by it. Similar to HashSet, LinkedHashSet elements are kept in hash tables.
☛ Related Questions: