put(K k, V v)

V put(K key, V value)
add the specified value with the specified key in this map.
 
/**
 *Output: 
 D: 99.22
 A: 3434.34
 C: 1378.0
 B: 123.22
 E: -19.08

 B's new balance: 1123.22
 */

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

public class MainClass {
  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());
    }
    System.out.println();

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

    System.out.println("B's new balance: " + tm.get("B"));
  }
}
  
Home 
  Java Book 
    Collection  

TreeMap:
  1. TreeMap Class
  2. new TreeMap<K, V> ()
  3. entrySet()
  4. firstKey()
  5. get(K k)
  6. headMap(K toKey)
  7. headMap(K toKey, boolean inclusive)
  8. higherKey(K key)
  9. lastKey()
  10. lowerKey(K key)
  11. put(K k, V v)
  12. TreeMap size()
  13. subMap(K fromKey, K toKey)
  14. tailMap(T fromKey)
  15. TreeMap values()