class Demo_Map{
publuic static void main(String[] args){
Map<String, Integer> map = new HashMap<String,Integer>();
map.put("老张",23);
map.put("老四",24);
map.put("老王",25);
Set<Map.Entry<String,Integer>> entrySet = map.entry();
Iterator<String,Integer> it = entry.iterator();
while(it.hasNest()){
Map.Entry<String , Integer> en = it.next(); //获取子类对象
String key = en.getKey(); //根据键值对对象获取键
Integer value = en.getValue(); //根据键值对获取值
System.out.println(key+"="+value);
}
}
}
|
|