Java Programming - Objects and Collections - Discussion
Discussion Forum : Objects and Collections - General Questions (Q.No. 12)
12.
You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
Answer: Option
Explanation:
Option A is correct. A Map cannot contain duplicate keys.
Option B is wrong. Lists typically allow duplicate elements.
Option C is wrong. Collection allows duplicate elements.
Discussion:
8 comments Page 1 of 1.
Moiz Nagourwala said:
9 years ago
Can an interface provide any type of capability?
I guess we just can't do anything than specifying the contract in terms of methods. So there is no way to forbid duplicate entries as methods are abstract.
I guess we just can't do anything than specifying the contract in terms of methods. So there is no way to forbid duplicate entries as methods are abstract.
Gautam prusty said:
9 years ago
Here you have written that,
You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
Ans- But, Map is not part of the collection, so the answer is (D).
You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
Ans- But, Map is not part of the collection, so the answer is (D).
Kirk said:
1 decade ago
This is simply a confusingly worded question.
If you consider Key/Value pairs as the element then the answer is correct, however if you only care about the Value then the answer is wrong.
I got it wrong, but I think that considering the Key/Value pair as the element is probably more correct.
I'd still give 1/2 points for selecting Map !
If you consider Key/Value pairs as the element then the answer is correct, however if you only care about the Value then the answer is wrong.
I got it wrong, but I think that considering the Key/Value pair as the element is probably more correct.
I'd still give 1/2 points for selecting Map !
Sonam said:
1 decade ago
Yes, the correct answer is D because the answer is asking about duplicate elements not the duplicate keys.
Saroj KUmar Das said:
1 decade ago
See Map don't contain duplicate keys but it contain duplicate values, it may be uses HashMap. I think the answer is D.
Dave Hampton said:
1 decade ago
The question is ambiguous. It does not refer to 'unique keys' - it just states 'no duplicates'. You can in fact have duplicate object values in a Map referenced by different keys. The answer to the question as it stands is java.util.Set which translates to answer D as it's not listed.
Chandra said:
1 decade ago
Map allow duplicates but I will overide with previous value. So we can, t say duplicate keys not allow.
Ashok said:
1 decade ago
I think its wrong because as the question is like collection that don't allow duplicate elements not the keys, so it must be option D.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers