List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:TreeMapDemo.java
public static void main(String args[]) { TreeMap<String, Double> tm = new TreeMap<String, Double>(); tm.put("A", new Double(3.34)); tm.put("B", new Double(1.22)); tm.put("C", new Double(1.00)); tm.put("D", new Double(9.22)); tm.put("E", new Double(-1.08)); Set<Map.Entry<String, Double>> set = tm.entrySet(); for (Map.Entry<String, Double> me : set) { System.out.print(me.getKey() + ": "); System.out.println(me.getValue()); }//from ww w. j a va2 s .c o m double balance = tm.get("A"); tm.put("B", balance + 1000); System.out.println(tm.get("A")); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> db = new TreeMap<Integer, String>(Collections.reverseOrder()); db.put(1000, "1000"); db.put(1011, "1011"); db.put(1102, "1102"); db.put(2023, "2023"); db.put(2034, "2034"); System.out.println(db);/*from w w w .j a v a2 s .c o m*/ }
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:MainClass.java
public static void main(String args[]) { TreeMap<String, Double> tm = new TreeMap<String, Double>(); tm.put("A", new Double(3434.34)); tm.put("B", new Double(123.22)); tm.put("C", new Double(1378.00)); tm.put("D", new Double(99.22)); tm.put("E", new Double(-19.08)); Set<Map.Entry<String, Double>> set = tm.entrySet(); for (Map.Entry<String, Double> me : set) { System.out.print(me.getKey() + ": "); System.out.println(me.getValue()); }/*w w w .j a va 2s . c o m*/ System.out.println(); double balance = tm.get("B"); tm.put("B", balance + 1000); System.out.println("B's new balance: " + tm.get("B")); }
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()); }
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 greatest key less than or equal to 4"); System.out.println("Value is: " + treemap.floorKey(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"); System.out.println("Checking floor entry for 6"); System.out.println("Value is: " + treemap.floorEntry(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("Checking value for key 3"); System.out.println("Value is: " + treemap.get(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 size of the map System.out.println("Size of the map: " + 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 key"); System.out.println("First key is: " + treemap.firstKey()); }