View
194
Download
1
Category
Preview:
DESCRIPTION
Citation preview
1
Set Interface
1
Set Interface It is introduce in 1.2 version of java.
It doesn't have any fixed type for generating the result .
It doesn't allow duplicacy but if we add duplicate elements
then it doesn't generate any error message it simply avoid
duplicate element.
1
Set Interface Some of the set depends on type of element and null.If we
add null or different-different type of elements then it can
generate NullPointerException and ClassCastException.
It doesn't support indexing means doesn't allow to insert
and delete elements at any particular position.
It is heterogeneous by nature but we can make
it homogeneous using generics.
1
HashSet It is used since 1.2 version of java.
It doesn't support duplicacy.
It doesn't guarantee any order for generating result even it
does not guarantee that the order will remain constant over
time.
It allow to add null as a element means doesn't generate
NullPointerException when 'null' is added as a elements.
1
HashSet It maintain Hashtable class for holding the set elements
internally.
It is not synchronized but we can make it synchronized
according to our requirement.
It is heterogeneous by nature but we can make
it homogeneous using generics.
1
TreeSet It is used since 1.2 version of java.
It doesn't support duplicacy.
It generate the order of result as ascending but we can also
generate result in descending order.
It is by-default homogeneous by nature.
1
TreeSet When we add heterogeneous type of elements then it
generate ClassCastException at run-time.
It doesn't need any explicit declaration of Comparator as
well as Comparable to perform sorting of elements ,it is
done automatically.
1
LinkedHashSet It is used since 1.4 version of java.
It doesn't support duplicacy.
It generate result in insertion order.
It is heterogeneous by nature but we can make
it homogeneous using generics.
It is Hashtable and LinkedList implementation of Set
interface.
1
LinkedHashSet It internally use doubly-linked-list for maintaining the
elements of LinkedHashSet.
To use it con-currently for multiple thread, explicitly create
the collection as synchronized using the Collections
class(Collections.synchronizedSet(Set s) ).
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on JAVA
Recommended