Map<String,Object> map = new HashMap<>();
map.put("name","zhongxu");
map.put("age",28);
map.put("sex","man");
map.put("love","JAVA");
map.put("major","Java后端开发工程师");
//使用lambda 的foreach便利hashmap
System.out.println("使用lambda表达式遍历HashMap:");
map.forEach((key,value)->{ System.out.println(key+"-------"+value); });
//使用stream遍历hashmap
System.out.println("使用stream遍历HashMap:");
map.entrySet().stream().forEach(entry->{System.out.println(entry.getKey()+"----"+entry.getValue()); });
关注我查看跟多文章