第一种:
Set<K> keys =map.keySet();
Iterator<K> ite = keys.iterator();
while(ite.hasNext())
{
K key = ite.next();
V value = map.get(key);
System.out.println(key+","+value);
}
第二种:
Set<Map.Entry<K,V>> entry = map.entrySet();
Iterator<Map.Entry<K,V>> ite = entry.iterator();
while(ite.hasNext())
{
Map.Entry<K,V> en = ite.next();
K key = en.getKey();
V value = en.getValue();
System.out.println(key+","+value);
}
Map的迭代方式小结
最新推荐文章于 2022-07-25 16:54:15 发布