It is required to create a collection which guarantees that no duplicate elements are sto
red. Which of the following would be the appropriate for this purpose:
Answers
Answered by
0
Answer:
Option B is correct. A set is a collection that contains no duplicate elements. The iterator returns the elements in no particular order . A map cannot contain duplicate keys but it may contain duplicate values.
Answered by
0
Correct question:
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in a natural order. Which interface provides that capability?
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.Collection
The correct option is (B). java.util.Set.
- A set is a group of elements that do not have any duplicates. The elements are returned in no particular order by the iterator (unless this set is an instance of some class that provides a guarantee).
- Although a map cannot have multiple keys, it can have duplicate values. Duplicate elements are allowed in List and Collection.
- A map's contents can be viewed as a bunch of keys, a group of numbers, or a collection of important translations using the Map interface's three collection views.
- A list is a group of items that have been arranged in a specific order (also known as a sequence). The user of this interface has complete control over where each element appears in the list.
#SPJ2
Similar questions