The TreeMap class belongs to java.util.package. The TreeMap is stored in the form of keys and values format, but it maintains ascending and sorting order by using their keys.
public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, Serializable
K: This is the type of key maintained in the TreeMap
V: This is the type of value maintained in the TreeMap
import java.util.TreeMap;class Main {public static void main(String[] args) {// Creating TreeMap of empIDTreeMap<String, Integer> empID = new TreeMap<>();// Using put()empID.put("John", 3);empID.put("Charlie",4);empID.put("Jack",5);System.out.println("TreeMap of empID:"+empID);}}
TreeMap from the util, and introduce the main class.empID.empID.empID using their keys.TreeMap. For example, remove method to remove the element.Method Name | Syntax | Usage |
clear | Tree_Map.clear() | The |
containsKey | Tree_Map.containsKey(key_element) | The |
containsValue | Tree_Map.containsValue(Object Value) | The |
get | Tree_Map.get(Object key_element) | The |
keySet | Tree_Map.keySet() | The |
put | Tree_Map.put(key, value) | The |
remove | Tree_Map.remove(Object key) | The |
size | Tree_Map.size(key) | The |
values | Tree_Map.values() | The |