TreeMap
TreeMap is store key
value pairs like HashMap. But it is sorted by key (ascending order) or by
Comparator provided at the map creation time and it design to work as a
red-black tree.
Red-black tree
Red-black
tree is a binary search tree with fallowing rules
·
Every node either red
or black
·
Every null nodes
consider as a black node
·
If node is red both
child nodes are black
·
Every path from node to
leaf contains the same number of black nodes
Check with your own
data set
Set
Is unique collection of
objects .There have three implementation of the Set, called HashSet, TreeSet
and LinkedHashSet
HashSet
Its unordered set.
Internally it use HashMap.Inside of HashSet class have class variable call ‘map’
which is an instance of the HashMap .when we adding values to the HashSet using
add(element) internally it add values to ‘map’ by calling put(key,value) .use
that element passing through the add method as a key and use dummy object as
value for all elements
Object value=new
Object();
HashMap internally
check the uniqueness of the Key objects using equal method
TreeSet
TreeSet is sorted and
internally using TreeMap.(functioning same like HashSet )
LinkedHashSet
LinkedHashSet is
ordered set which extends the HashSet.It uses Doubly Linked List for hold the
order.
No comments:
Post a Comment