java how to insert key in treemap code example
Example: TreeMap put() method in java
import java.util.TreeMap;
public class TreeMapPutMethodExample
{
public static void main(String[] args)
{
TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
tm.put(32, "pineapple");
tm.put(51, "watermelon");
tm.put(38, "grapes");
tm.put(69, "mango");
tm.put(58, "apple");
System.out.println("TreeMap before using put(K key, V value) method: " + tm);
System.out.println("Value is: " + tm.put(38, "banana"));
System.out.println("TreeMap after using put(K key, V value) method: " + tm);
}
}