java中lamda表达式用法
map-> list
Map<String, Object> map = new HashMap<>(); List<String> list = new ArrayList<>(); map.forEach((k, v) -> { list.add(v.toString()); });
list->map
@Data
public class TestEntity { private String code; private String name; } List<TestEntity> list = new ArrayList<>(); Map<String, TestEntity > map = list.stream().collect( Collectors.toMap(item -> ((TestEntity )item).getCode, item -> (TestEntity)item) );