Tree Map
Tree Map is not a part of the Collection interface and it is
available in “java.util” package.
Java Tree Map extends Abstract Map class, and it implements Navigable
Map, Cloneable, Serializable interfaces.
Java Tree Map maintains ascending order.
Java Tree Map contains only unique elements.
Java Tree Map contains values based on the key.
Java Tree Map cannot have a null key but can have multiple
null values.
Java Tree Map is non synchronized.
Creation of TreeMap:
Syntax:
TreeMap< k, V > map=new TreeMap< k, V >();
Here, k represents key, v represent value.
Methods of TreeMap:
Some of the important methods in TreeMap
put(k, v): this method is used to associates the specified
value with the specified key in this map. If the map previously contained a
mapping for the key, the old value is replaced.
clear(): this method is used to removes all of the mappings
from this map. The map will be empty after this call returns.
ceilingEntry(key): this method returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.
ceilingKey(key): this method returns least key greater
than or equal to the given key, or null if there is no such key.
descendingMap(): this method returns a reverse order view
of this map.
Java Program:
Output:
No comments:
Post a Comment