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) {
    SortedMap<String, Integer> sortedMap = new TreeMap<String, Integer>();
    sortedMap.put("A", 1);
    sortedMap.put("B", 2);
    sortedMap.put("C", 3);
    sortedMap.put("D", 4);
    sortedMap.put("E", 5);
    sortedMap.put("java2s", 6);

    SortedMap<String, Integer> map = sortedMap.subMap("B", "E");
    System.out.println(map);/* w w  w .  j ava2  s . c o  m*/

}

From source file:Main.java

public static void main(String[] args) {
    SortedMap<String, String> sMap = new TreeMap<>();
    sMap.put("CSS", "style");
    sMap.put("HTML", "mark up");
    sMap.put("Oracle", "database");
    sMap.put("XML", "data");

    SortedMap<String, String> subMap = sMap.subMap("CSS", "XML");
    System.out.println(subMap);//from  w w  w  .  j  a  v a 2s.  c  om

    // Get the first and last keys
    String firstKey = sMap.firstKey();
    String lastKey = sMap.lastKey();
    System.out.println("First Key:  " + firstKey);
    System.out.println("Last key:   " + lastKey);
}

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("Getting tail map");
    SortedMap<Integer, String> treemapincl = treemap.tailMap(3);
    System.out.println("Tail map values: " + treemapincl);
}

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("Getting a portion of the map");
    SortedMap<Integer, String> treemapincl = treemap.subMap(1, 5);
    System.out.println("Sub map values: " + treemapincl);
}

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("Getting tail map");
    SortedMap<Integer, String> treemapincl = treemap.tailMap(3, true);
    System.out.println("Tail map values: " + treemapincl);
}

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

    // creating set
    Set set = treemap.keySet();//from w  ww . j av  a2s .co  m

    // getting set view         
    System.out.println("Checking values of the set");
    System.out.println("Value is: " + set);
}

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("Ceiling entry for 4: " + treemap.ceilingEntry(4));
    System.out.println("Ceiling entry for 5: " + treemap.ceilingEntry(5));
}

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 value");
    System.out.println("'three' exists: " + treemap.containsValue("three"));
}

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 key value 6");
    System.out.println("Value for key 6 exists: " + treemap.containsKey(6));
}

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("Getting collection from the map");
    Collection<String> coll = treemap.values();
    System.out.println("Value of the collection: " + coll);
}