You need to store elements in a collection that guarantees that no duplicates are stored. Which two interfaces provide that capability? (Choose Two) A. java.util.Map B. java.util.Set C. java.util.List D. java.util.StoredSet E. java.util.StoredMap F. java.util.Collection Ans: B,D�.
For Map,wheather two objects are equal or not ,depends on equals method.If you won't override equals method ,no two objects are never equal,even if they are equal.
Yes Anil, but the same holds for Set and SortedSet - if the equals() method of the objects you put in always returns false, even if the objects are really equal, then you can store duplicates in a Set. It would be an ugly hack, and really a bug in your equals() method if you do this.
A Map stores key-value pairs. The keys have to be unique, but the values do not have to be unique. So a Map doesn't protect against duplicate values. However, the question is a little bit ambiguous. Indeed, you cannot have duplicate key-value pairs in a map.
Collections come in four basic flavors: - Lists Lists of things (classes that implement List). - Sets Unique things (classes that implement Set). - Maps Things with a unique ID (classes that implement Map). - Queues Things arranged by the order in which they are to be processed.
That points to Set and Sorted set as the answer.
Maps store unique IDs, but IDs are not the elements you store, they are only identifiers you use to find your elements. Maps will store duplicate elements and Sets will not.