Java8里的HashMap对象lambda遍历方法

Java demo:

        Map<String, User> map = new HashMap<>();
        map.put("id1", new User(1,"name1"));
        map.put("id2", new User(2,"name2"));

        String str = map.entrySet().stream().map(entry ->
            "id[" + entry.getKey() + "], code=" + entry.getValue().getCode() + ", text=" + entry.getValue().getText()
        ).collect(Collectors.joining("; "));
        System.out.println("str==="+str);

 

end.

posted on 2020-06-30 11:40  梦幻朵颜  阅读(3268)  评论(0编辑  收藏  举报