map的两种取值方式
2016-02-26 21:08
435 查看
public class MapUtil{ public static void iteratorMap1(Map m) { Set set=m.keySet();//用接口实例接口 Iterator iter = set.iterator(); while (iter.hasNext()) {//遍历二次,速度慢 String k=(String)iter.next(); System.out.println(k +"="+ m.get(k)); //System.out.println(iter.next()+"="+ m.get(iter.next())); //因为指针判断下一个有没有值 iter.next是当前对象 但是 m.get(iter.next())是下一个值 } public static void iteratorMap2(Map m){ Iterator i=m.entrySet().iterator(); while(i.hasNext()){//只遍历一次,速度快 Map.Entry e=(Map.Entry)i.next(); System.out.println(e.getKey()+"="+e.getValue()); //System.out.println(e.setValue(""));//返回value的值 } }
相关文章推荐
- css中的BFC
- Hibernate inverse和cascade的作用和区别
- <LeetCode OJ> 96. Unique Binary Search Trees
- mac Zip 常用命令
- C\C++中内存分几个区
- UVALive 3026(KMP)
- Big Event in HDU (HDU_1171) 01背包
- 新手学习opencv七:svm
- MFC 程序隐藏界面
- JavaSE入门学习23:Java面向对象之构造方法
- Zookeeper集群和HBase集群
- LeetCode----Product of Array Except Self
- Python基础回顾之-变量和数据类型
- 数字图像处理-编程实现染色体计数 C语言实现
- Tornado路由
- HDU 5631 Rikka with Graph 求从n+1 边中删除一些边使图依然联通
- 根据自己的理解描述下Android数字签名?
- mono下使用Nhibernate
- ACM_模板_求质因子
- 资本资产定价模型