java中lamda表达式用法


map-> list

        Map map = new HashMap<>();
        List list = new ArrayList<>();
        map.forEach((k, v) -> {
            list.add(v.toString());
        });

list->map

@Data
public
class TestEntity { private String code; private String name; } List list = new ArrayList<>(); Map map = list.stream().collect( Collectors.toMap(item -> ((TestEntity )item).getCode, item -> (TestEntity)item) );