In this example, we may learn how to use TreeMap. We may also see how to add something to TreeMap and how to retrieve the value added from TreeMap.
Source Code
package com.beginner.examples;
import java.util.TreeMap;
public class CreatTreeMap {
public static void main(String[] args) {
//create TreeMap.
TreeMap treeMap = new TreeMap();
/*
* Add key value pair to TreeMap using put method of Java TreeMap.
*/
treeMap.put("1", "Alice");
treeMap.put("2", "Bob");
treeMap.put("3", "Jack");
}
}
References
Imported packages in Java documentation: