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)
(02)Map<String,Integer>maps=new HashMap<String,Integer>();获得键值对的value值,组成集合,之所以使用collection集合,没有为什么,看API,返回的是Collection集合,所以使用collection,很多东西在API里面都有,在以后学习过程中要是善于使用API文档解决问题,多读读。Collection <Integer>c=e();
(03)map集合中value值有可能是重复的,使用这种方式可以获得value值,但是不能获得keyfor(Integer i:c)
(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())}
(05)//第三种:推荐,尤其是容量大时 tln("通过ySet遍历key和value"); for (y<Integer, String> entry : ySet()) { tln("key= " + ey() + " and value= " + alue()); }
(06)tln("通过ySet使用iterator遍历key和value:"); //迭代器模式 把集合中的数据 临时用迭代器的表示 Iterator<y<Integer, String>> it = ySet()ator(); while (ext())
推荐使用Setsets=yset();