keySet() returns the key set
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class Main {
public static void main(String[] args) {
HashMap<String, String> hMap = new HashMap<String, String>();
hMap.put("1", "One");
hMap.put("2", "Two");
hMap.put("3", "Three");
Set st = hMap.keySet();
Iterator itr = st.iterator();
while (itr.hasNext())
System.out.println(itr.next());
// remove 2 from Set
st.remove("2");
System.out.println(hMap.containsKey("2"));
}
}
Home
Java Book
Collection
Java Book
Collection
HashMap:
- HashMap Class
- new HashMap<K, V>()
- clear() removes all elements in a HashMap
- clone() creates a copy of the HashMap
- containsKey(Object key) checks to see if the HashMap has that key
- containsValue(Object value) checks if the HashMap has that value
- entrySet() returns the key-value pair as a set
- keySet() returns the key set
- get(E o) returns the value by the key
- put(E o, E o1) add value and key to a HashMap
- putAll(Map<?, ?> m) adds another map
- remove(Object key) deletes an entry by a key
- size() returns the size of a HashMap
- values() returns the value of the