HashMap集合遍历方法 //创建集合 Map hashMap=new HashMap<>(); hashMap.put(1,"小贾"); hashMap.put(2,"小王"); //遍历方法 Set<Map.Entry<String,Long>> entries= hashMap.entrySet(); for(Map.Entry<String,Long> entry:entries){ System.out.println(entry.getKey()+entry.getValue()); }