TreeMap : TreeMap « Collections Data Structure « Java



import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

class TreeMapDemo {
  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() + ": ");

    double balance = tm.get("A");
    tm.put("B", balance + 1000);



Related examples in the same category

1.Read file content and save to a TreeMap
2.Get Synchronized Map from Java TreeMap
3.Check if a particular key exists in Java TreeMap
4.Get Set view of Keys from Java TreeMap
5.Get Tail Map from Java TreeMap
6.Get Size of Java TreeMap
7.Remove value from Java TreeMap
8.Iterate through the values of Java TreeMap
9.Check if a particular value exists in Java TreeMap
10.Remove all values from Java TreeMap
11.Get Sub Map from Java TreeMap
12.Get lowest and highest key stored in Java TreeMap
13.Get Head Map from Java TreeMap
14.Use Generic TreeMap to store Integer as key and String as value