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) );
原文:https://www.cnblogs.com/blue-rain/p/14055456.html