1.

How to remove duplicates from List?(a) HashSet listToSet = new HashSet(duplicateList);(b) HashSet listToSet = duplicateList.toSet();(c) HashSet listToSet = Collections.convertToSet(duplicateList);(d) HashSet listToSet = duplicateList.getSet();The question was asked in an international level competition.This is a very interesting question from Data Structures-List in portion java.util – The Collections Framework of Java

Answer»

Correct OPTION is (a) HASHSET listToSet = NEW HashSet(duplicateList);

Explanation: Duplicate elements are ALLOWED in List. Set contains UNIQUE objects.



Discussion

No Comment Found

Related InterviewSolutions