get(E o) returns the value by the key

 
/**
 *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.HashMap;
import java.util.Map;
import java.util.Set;

public class MainClass {
  public static void main(String args[]) {

    HashMap<String, Double> hm = new HashMap<String, Double>();

    hm.put("A", new Double(3434.34));
    hm.put("B", new Double(123.22));
    hm.put("C", new Double(1378.00));
    hm.put("D", new Double(99.22));
    hm.put("E", new Double(-19.08));

    Set<Map.Entry<String, Double>> set = hm.entrySet();

    for (Map.Entry<String, Double> me : set) {
      System.out.print(me.getKey() + ": ");
      System.out.println(me.getValue());
    }

    System.out.println();

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

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

HashMap:
  1. HashMap Class
  2. new HashMap<K, V>()
  3. clear() removes all elements in a HashMap
  4. clone() creates a copy of the HashMap
  5. containsKey(Object key) checks to see if the HashMap has that key
  6. containsValue(Object value) checks if the HashMap has that value
  7. entrySet() returns the key-value pair as a set
  8. keySet() returns the key set
  9. get(E o) returns the value by the key
  10. put(E o, E o1) add value and key to a HashMap
  11. putAll(Map<?, ?> m) adds another map
  12. remove(Object key) deletes an entry by a key
  13. size() returns the size of a HashMap
  14. values() returns the value of the