07 | 09 | 2010
Main Menu
Affiliates
Login Form



Alexa
JoomlaWatch Stats 1.2.6 by Matej Koval
Java Collections Interview Questions - Sets
Written by Java King   
Sunday, 18 May 2008 01:44
Article Index
Java Collections Interview Questions
Sets
Maps
All Pages

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.

 



Comments
Search
Pannaga   |203.200.31.xxx |2009-06-25 04:21:48
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Sunday, 12 April 2009 09:10 )