Java Collection Tutorial - Java TreeMap() Constructor


TreeMap() constructor from TreeMap has the following syntax.

public TreeMap()


In the following code shows how to use TreeMap.TreeMap() constructor.

import java.util.TreeMap;
// w w w. ja v  a2s . co  m
public class Main {

  public static void main(String[] args) {
    TreeMap<Integer, String> db = new TreeMap<Integer, String>();
    db.put(1000, "1000");
    db.put(1011, "1011");
    db.put(1102, "1102");
    db.put(2023, "2023");
    db.put(2034, "2034");

    System.out.println("First key lower than 2034: " + db.lowerKey(2034));

The code above generates the following result.