List of usage examples for java.util TreeMap TreeMap
public TreeMap()
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"); // getting higher entry for key 4 System.out.println("Checking values of the map"); System.out.println("Value is: " + treemap.higherEntry(4)); }
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"); // getting higher key for key 4 System.out.println("Checking values of the map"); System.out.println("Value is: " + treemap.higherKey(3)); }
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"); // getting the value with greatest key System.out.println("Checking last entry"); System.out.println("Value is: " + treemap.lastEntry()); }
From source file:Main.java
public static void main(String[] a) { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); if (!map.isEmpty()) { String last = map.lastKey(); boolean first = true; do {//ww w .j a v a 2s . c om if (!first) { System.out.print(", "); } System.out.print(last); last = map.headMap(last, true).lastKey(); first = false; } while (last != map.firstKey()); System.out.println(); } }
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"); // polling first entry System.out.println("Value before poll: " + treemap); System.out.println("Value returned: " + treemap.pollFirstEntry()); System.out.println("Value after poll: " + treemap); }
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"); // polling last entry System.out.println("Value before poll: " + treemap); System.out.println("Value returned: " + treemap.pollLastEntry()); System.out.println("Value after poll: " + treemap); }
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("Value before modification: " + treemap); // removing value at key 5 System.out.println("Removed value: " + treemap.remove(5)); System.out.println("Value after modification: " + treemap); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); TreeMap<Integer, String> treemapclone = 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"); // cloning tree map System.out.println("Cloning tree map"); treemapclone = (TreeMap) treemap.clone(); System.out.println("Original map: " + treemap); System.out.println("Cloned map: " + treemapclone); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); TreeMap<Integer, String> treemap_putall = 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"); treemap_putall.put(1, "1"); treemap_putall.put(2, "2"); treemap_putall.put(7, "7"); System.out.println("Value before modification: " + treemap); // Putting 2nd map in 1st map treemap.putAll(treemap_putall);/*w ww .j a v a 2 s . c o m*/ System.out.println("Value after modification: " + treemap); }
From source file:Main.java
public static void main(String[] args) { TreeMap treeMap = new TreeMap(); Map map = Collections.synchronizedMap(treeMap); }