在这里插入代码片
```public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>();
map.put("wy","王小胖");
map.put("smh","施小呆");
System.out.println("******方法一:entrySet遍历(性能最优)******");
for(Map.Entry<String ,String> m : map.entrySet()){
System.out.println(m.getKey()+":"+m.getValue());
}
System.out.println("******方法二:使用for循环遍历k或者v******");
//遍历key
for (String key : map.keySet()) {
System.out.println(key);
}
//遍历value
for (String value : map.values()) {
System.out.println(value);
}
System.out.println("******方法三:通过Iterator遍历得到看k,v******");
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
System.out.println(entry.getKey()+"和"+entry.getValue());
}
System.out.println("******方法四:使用java8的Lambda******");
map.forEach((k, v) -> {
//直接遍历出key和value
System.out.println(k + " : " + v);
});
}