java hashmap getkey code example
Example 1: hashmap get value java
//Import Hashmap
import java.util.HashMap;
HashMap<String, String> dir = new HashMap<String, String>();
//Add key, values
dir.put("hi", "hello");
dir.put("wow", "amazing");
//print value for hi.
System.out.println(dir.get("hi");
Example 2: java hashmap get array of keys
for (int key : myHashMap.keySet()){
// do stuff
}
Example 3: java get keys from hashmap
//returns as set
hashmap.keySet()