Create a TreeMap mapping from String to double in Java
Description
The following code shows how to create a TreeMap mapping from String to double.
Example
/* w w w.jav a2 s. c o m*/
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class Main {
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());
}
double balance = tm.get("A");
tm.put("B", balance + 1000);
System.out.println(tm.get("A"));
}
}
The code above generates the following result.