1 package com.lanxi.demo1_1_1; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.Map; 6 import java.util.Map.Entry; 7 8 public class Test { 9 public static void main(String[] args) { 10 Map map=new HashMap(); 11 map.put(123, "张三"); 12 map.put(456, "李四"); 13 map.put(789, "王五"); 14 System.out.println("keySet:"+map.keySet()); 15 Iterator it=map.entrySet().iterator(); 16 while(it.hasNext()){ 17 Entry en=(Entry)it.next(); 18 System.out.println("entrySet:"+en.getKey()); 19 } 20 } 21 }
结果显示