遍历hashmap的键值一,通过 keySet()方法

来源:互联网 发布:c语言实战演练 编辑:程序博客网 时间:2024/05/19 00:38
/** * 遍历hashmap的键值,通过 keySet()方法 * @author gulijiang * */public class HashMapTest1 {public static void main(String[] args) {HashMap hashMap = new HashMap();hashMap.put("a", "aa");hashMap.put("b","bb");hashMap.put("c","cc");print(hashMap);}private static void print(HashMap hashMap) {Set set = hashMap.keySet();for (Iterator iterator = set.iterator(); iterator.hasNext();) {String key = (String)iterator.next();System.out.println(key);System.out.println(hashMap.get(key));}}}