Http://blog.csdn.net/u011240877/article/category/6447444/1
The map interface provides three angles to analyze the map:
- Keyset:keyset is a collection of key (key) in a Map, saved as set , and not allowed to be duplicated, so the objects stored by the key need to override the Equals () and Hashcode () methods. Can be obtained through the Map.keyset () method.
- Using KeySet traversal:
Set set = map.keySet(); for (Object key : set) { System.out.println(map.get(key)); }
- Values:values is a collection of MAP values (value) that is saved as Collection and therefore can be duplicated. Can be obtained through the Map.values () method.
- Use the values traversal:
-
Collection values = map.values(); Iterator iterator = values.iterator(); while (iterator.hasNext()){ System.out.println("value " + iterator.next()); }
- Entry:entry is a static internal interface in the map interface that represents a mapping of a key-value pair, such as the Key1-value1 group mapping relationship.
-
- GetKey (), gets the key in this set of mappings
- GetValue (), gets the values in this set of mappings value
- SetValue (), modify the values in this set of mappings
- Hashcode (), returns the hash value of this Entry
- Equals (), compares key-value for equality
The Map.entryset () method obtains a set of Entry that are stored in the set so that the Entry in the MAP cannot be duplicated.
public Set<Map.Entry<K,V>> entrySet();
- using Entry traversal
Set entrySet = map.entrySet(); for (Object o : entrySet) { Map.Entry entry = (Map.Entry) o; System.out.println(entry); //key=value System.out.println(entry.getKey() + " / " + entry.getValue()); }
- *************************************************************************************************************** ***************
Java Collection Map&hashmap