package com.lanxi.demo1_1_1;

 import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry; public class Test {
public static void main(String[] args) {
Map map=new HashMap();
map.put(123, "张三");
map.put(456, "李四");
map.put(789, "王五");
System.out.println("keySet:"+map.keySet());
Iterator it=map.entrySet().iterator();
while(it.hasNext()){
Entry en=(Entry)it.next();
System.out.println("entrySet:"+en.getKey());
}
}
}

结果显示

定义一个Map集合,key和value不规定类型,任意放入数据,用keySet()和    entrySet()两种方式遍历出Map集合的数据-LMLPHP

05-11 09:03