职场就业

当前位置 /首页/职场理财/职场就业/列表

map集合的遍历方式

map集合内的元素key值不能相同,value值可以相同;hashmap经常和map一起使用
Map<String ,Integer>maps=new HashMap<String,String>();

操作方法

(01)map集合的遍历方式1,通过获得key值遍历map集合Map<String ,Integer> maps=new HashMap<String,Integer>();String [] strs=et();for(String s:strs)

map集合的遍历方式

(02)Map<String,Integer>maps=new HashMap<String,Integer>();获得键值对的value值,组成集合,之所以使用collection集合,没有为什么,看API,返回的是Collection集合,所以使用collection,很多东西在API里面都有,在以后学习过程中要是善于使用API文档解决问题,多读读。Collection <Integer>c=e();

map集合的遍历方式 第2张

(03)map集合中value值有可能是重复的,使用这种方式可以获得value值,但是不能获得keyfor(Integer i:c)

map集合的遍历方式 第3张

(04)Map<String,Integer>=new HashMap<String,Integer>();//获得键值对集合,Set<y<String,Integer>>sets=yset();for(y<String,Integer  e:sets>){tln("key="+ey()+",value="+alue())}

map集合的遍历方式 第4张

(05)//第三种:推荐,尤其是容量大时    tln("通过ySet遍历key和value");    for (y<Integer, String> entry : ySet()) {     tln("key= " + ey() + " and value= " + alue());    }

map集合的遍历方式 第5张

(06)tln("通过ySet使用iterator遍历key和value:");    //迭代器模式   把集合中的数据  临时用迭代器的表示    Iterator<y<Integer, String>> it = ySet()ator();    while (ext())

map集合的遍历方式 第6张

特别提示

推荐使用Setsets=yset();

TAG标签:map 遍历 #