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<Integer, Product> db = new TreeMap<Integer, Product>();
    db.put(1000, new Product("D", 350));
    db.put(1011, new Product("p", 15.75));
    db.put(1102, new Product("M", 8.50));
    db.put(2023, new Product("A", 150));
    db.put(2034, new Product("T", 9.99));

    System.out.println(db.subMap(1000, 1999) + "\n");

    System.out.println(db.tailMap(1011) + "\n");

    System.out.println(db.headMap(2023));

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

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.descendingMap() + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.descendingKeySet() + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.tailMap(1) + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.subMap(1, 2) + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.subMap(1, false, 2, false) + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.navigableKeySet() + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.tailMap(1, true) + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.headMap(1) + "\n");

}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println(map.headMap(1, false) + "\n");

}