public static void main(String[] args) {
Map map = new HashMap();
map.put("1", "value1");
map.put("2", "value2");
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object val = entry.getValue();
System.out.println(key);
System.out.println(val);
Map map = new HashMap();
map.put("1", "value1");
map.put("2", "value2");
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object val = entry.getValue();
System.out.println(key);
System.out.println(val);
}
}
本文详细介绍了Java中使用Map集合存储数据,并通过Iterator进行遍历和打印的方法,包括如何获取键值对、获取键和值等操作。
3041

被折叠的 条评论
为什么被折叠?



