1.1. 通过key得到value
//得到所有的key值 Set<String> keySet = map.keySet(); //根据key值得到value值 for (String key : keySet) { System.out.println(key+":"+map.get(key)); } |
1.2. 通过entry得到key和value
//得到所有的entry Set<Entry<String, String>> entrySet = map.entrySet(); //从entry中得到key和value值 for (Entry<String, String> entry : entrySet) { System.out.println(entry.getKey()+":"+entry.getValue()); } |
1.3. 完整示例代码
MapTest.java |
|