Java Collection Tutorial - Java TreeMap(Map <? extends K ,? extends V > m) Constructor








Syntax

TreeMap(Map <? extends K ,? extends V > m) constructor from TreeMap has the following syntax.

public TreeMap(Map <? extends K ,? extends V> m)

Example

In the following code shows how to use TreeMap.TreeMap(Map <? extends K ,? extends V > m) constructor.

//w w  w . j av  a2 s  .  co m
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Main {

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

    TreeMap<Integer, String> db2 = new TreeMap<Integer, String>(db);
    
    System.out.println(db2);
  }
}

The code above generates the following result.