Example usage for java.util TreeMap TreeMap

List of usage examples for java.util TreeMap TreeMap

Introduction

In this page you can find the example usage for java.util TreeMap TreeMap.

Prototype

public TreeMap() 

Source Link

Document

Constructs a new, empty tree map, using the natural ordering of its keys.

Usage

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    System.out.println(treeMap.containsKey("1"));
}

From source file:Main.java

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));
}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();

    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    System.out.println(treeMap.containsValue("Three"));
}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    treeMap.clear();// w  ww  .  j a v a2  s. c  om
    System.out.println(treeMap.size());
}

From source file:Main.java

public static void main(String[] a) {

    TreeMap map = new TreeMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    if (!map.isEmpty()) {
        Object last = map.lastKey();
        boolean first = true;
        do {/* www .  j av  a2s .  com*/
            if (!first) {
                System.out.print(", ");
            }
            System.out.print(last);
            last = map.headMap(last).lastKey();
            first = false;
        } while (last != map.firstKey());
        System.out.println();
    }
}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();

    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    Object obj = treeMap.remove("2");
    System.out.println(obj + " Removed from TreeMap");
}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");
    treeMap.put("4", "Four");
    treeMap.put("5", "Five");

    System.out.println("Lowest key: " + treeMap.firstKey());
    System.out.println("Highest key: " + treeMap.lastKey());
}

From source file:MainClass.java

public static void main(String[] a) {

    TreeMap map = new TreeMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    Map map2 = map.headMap("key2");
    System.out.println(map2);//from  ww w.  j av  a 2s .co  m
}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    System.out.println("Size of TreeMap : " + treeMap.size());

    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    System.out.println("Size of TreeMap after addition : " + treeMap.size());
    treeMap.remove("2");
    System.out.println("Size of TreeMap after removal : " + treeMap.size());

}

From source file:Main.java

public static void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    System.out.println("Checking first entry");
    System.out.println("First entry is: " + treemap.firstEntry());
}