HashMap遍历的方式,推荐使用entrySet()
2015-03-09 22:11
309 查看
Iterator<Entry<x,x>> it = hashmap.entryset().iterator();
Map的entrySet()方法返回一个实现Map.Entry接口的对象集合。集合中每个对象都是底层Map中一个特定的键/值对。
方法:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
效率高,以后一定要使用此种方式!
相关文章推荐
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- HashMap遍历的两种方式,推荐使用entrySet()
- 对于Java中Map的遍历方式,很多文章都推荐使用entrySet
- HashMap遍历,推荐使用entrySet()
- 谨慎使用keySet:对于HashMap的2种遍历方式比较
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- Java HashMap推荐使用此方式!
- HashMap遍历使用entrySet的效率真的比keyset高?
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历 .
- HashMap遍历的两种方式,entrySet()和keySet()
- 【Map使用】Java中HashMap遍历的两种方式