| Java Collections Interview Questions - Sets |
| Written by Java King | ||||||||||||||
| Sunday, 18 May 2008 01:44 | ||||||||||||||
Page 2 of 3 Q: What is a Set? A: A set is a collection of Objects in which duplicates are not allowed, it models the mathematical set.
Q: What are the main Implementations of the Set interface? A: HashSet, TreeSet, LinkedHashSet and EnumSet?
Q: What is an EnumSet? A: An EnumSet is a specialized set for use with enum types, all of the elements in the EnumSet type that is specified, explicitly or implicitly, when the set is created.
Q: What is a HashSet? A: A HashSet is an Implementation of the SetInterface which internally uses a Hash Table like datastructure(actually elements are stored as keys in a HashMap) structure. It does not guarantee that the insersion order will be maintained and order may not remain constant with time.
Q: What is a TreeSet? A: TreeSet is a Set implementation that keeps the elements in sorted order. The elements are sorted according to the natural order of elements or by the comparator provided at creation time.
Q: Are HashSet and TreeSet thread safe? A: Both are not thread safe.
Only registered users can write comments!
Powered by !JoomlaComment 3.22
3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."
|
||||||||||||||
| Last Updated ( Sunday, 12 April 2009 09:10 ) | ||||||||||||||