十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
Map实现遍历的方法有哪些?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
Map获取键值
Map以按键/数值对的形式存储数据,和数组非常相似,在数组中存在的索引,它们本身也是对象。
Map的接口
Map---实现Map
Map.Entry--Map的内部类,描述Map中的按键/数值对。
SortedMap---扩展Map,使按键保持升序排列
关于怎么使用,一般是选择Map的子类,而不直接用Map类。
下面以HashMap为例
public static void main(String args[]) { HashMap hashmap =new HashMap(); hashmap.put("Item0", "Value0"); hashmap.put("Item1", "Value1"); hashmap.put("Item2", "Value2"); hashmap.put("Item3", "Value3"); Set set=hashmap.entrySet(); Iterator iterator=set.iterator(); while (iterator.hasNext() { Map.Entry mapentry = (Map.Entry) iterator.next(); System.out.println(mapentry.getkey()+"/"+ mapentry.getValue()); } }