标签:integer text color vps code ref set sys next
一般情况下,要输出Map中的key 和 value 是先得到key的集合,然后再迭代(循环)由每个key得到每个value
而Entry可以一次性获得这两个值
Set set = map.keySet(); //keySet() for(Iterator iter = set.iterator();iter.hasNext();) { String key = (String)iter.next(); //先获得键key Integer value = (Integer)map.get(key); //再由键获得value System.out.println(key + "=" + value); } -------------------------------------------------------------------------- Set set = map.entrySet(); //entrySet() for(Iterator iter = set.iterator();iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); String key = (String)entry.getKey(); //一次性获得键和值 key和value String value = (String)entry.getValue(); System.out.println(key + ": " + value); }
标签:integer text color vps code ref set sys next
原文地址:https://www.cnblogs.com/kdy11/p/8777511.html