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"); System.out.println("Ceiling key entry for 4: " + treemap.ceilingKey(4)); System.out.println("Ceiling key entry for 5: " + treemap.ceilingKey(5)); System.out.println("Ceiling key entry for 7: " + treemap.ceilingKey(7)); }
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"); NavigableMap<Integer, String> treemapincl = treemap.subMap(1, true, 3, true); 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>(); TreeMap<Integer, String> treemaphead = 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 head map treemaphead = treemap.headMap(3);/*from w ww. ja va2 s . c o m*/ System.out.println("Checking values of the sorted map"); System.out.println("Value is: " + treemaphead); }
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"); // putting values in navigable set NavigableSet nset = treemap.descendingKeySet(); System.out.println("Checking value"); System.out.println("Navigable set values: " + nset); }
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"); // putting values in navigable map NavigableMap nmap = treemap.descendingMap(); System.out.println("Checking value"); System.out.println("Navigable map values: " + nmap); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); TreeMap<Integer, String> treemapheadincl = 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 head map inclusive 3 treemapheadincl = treemap.headMap(3, true); System.out.println("Checking values of the map"); System.out.println("Value is: " + treemapheadincl); }
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("Entries in the Map: " + treemap); // clearing the map System.out.println("Clearing the Map"); treemap.clear();//from w w w . j a v a2s . c o m System.out.println("Entries in the Map: " + treemap); }
From source file:Freq.java
public static void main(String args[]) { Map m = new TreeMap(); m.put("a Key", "a Value"); m.put("Java2s", "www.java2s.com"); System.out.println(m.size() + " keys detected:"); System.out.println(m);//w w w.j a v a 2 s . c om }
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("3", "Three"); treeMap.put("2", "Two"); Set st = treeMap.keySet();//w w w.j ava2s .co m Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } st.remove("1"); System.out.println(treeMap.containsKey("1")); }
From source file:Main.java
public static void main(String[] args) { Map<String, int[]> map = new TreeMap<String, int[]>(); int[] array = new int[3]; array[0] = 0;/*from w w w . ja va 2s.c om*/ array[1] = 1; array[2] = 2; map.put("array", array); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String arrayName = iter.next(); array = map.get(arrayName); System.out.print(arrayName + ":"); for (int i = 0; i < array.length; i++) { System.out.print(array[i]); } } }