public static void main(String[] args){
Map map=new HashMap();
map.put("1", 21);
map.put("2", 123);
map.put("3", 98);
// 方法1 此方法效率比较高
Iterator ite=map.entrySet().iterator();
while(ite.hasNext()){
Entry string=(Entry)ite.next();
System.out.print(string.getKey()+"/");
System.out.println(string.getValue());
}
// 方法2 此方法效率比较低
Iterator iteKey=map.keySet().iterator();
while(iteKey.hasNext()){
Object key=iteKey.next();
Object value=map.get(key);
System.out.print(key+"/");
System.out.println(value);
}
// 方法3
Set<Entry<String, Integer>> set = map.entrySet();
for(Entry<String, Integer> entry: set)
{
System.out.println(entry.getKey() + "/" + entry.getValue());
}
}
取HashMap集合中的key和value的三种方法
原创mb64a401e9f23d4 博主文章分类:算法及数据结构 ©著作权
文章标签 javascript ViewUI System 文章分类 Oracle 数据库
上一篇:字符串中不分大小写的替换
下一篇:ArrayList集合总结

-
Java遍历Map集合的三种方法
遍历map集合的三种方法
java 遍历 System map集合 -
Java遍历List集合的三种方法
Java遍历List集合的三种方法
java for循环 集合类 i++ 迭代