遍历map的几种方法

1、for循环

针对key遍历:

for(Object  o : Map.keySet()){

Object value = map.getKey(0);

.......

}

针对Entry遍历

for( Map.Entry entry : Map.entrySet()){

Object key = entry.getKey();

Object value = entry.getVaule();

.......

}


2、while循环

针对key的遍历

Iterator it = emails.entrySet().iterator();

while( it.hasNext()){

Object value = map,getKey(it);

......

}

针对Entry的遍历

Iterator it = map.entrySet().itetator();

while ( it .hasNext() ){

Object key = it.getKey();

Object value =  it.getValue();

}




你可能感兴趣的:(object,iterator)