1转成⼀对⼀的,⼀个字段对应⼀个对象
`Map<Long, DeviceSpareType> maps = deviceRepairTypes.stream().collect(Collectors.toMap(DeviceSpareType::getId, Function.identity(), (key1, key2) -> key2));`
后⾯的key1,key2 是指定⼀种覆盖规则,防⽌key冲突
2.⼀个字段对应⼀个对象属性
Map<Long, String> maps = deviceRepairTypes.stream().collect(Collectors.toMap(DeviceSpareType::getId, DeviceSpareType::getAge, (key1, key2) -> key2));
3.⼀个字段对应多个对象
Map<Long, List<DeviceSpareType>> groupBy = deviceRepairTypes.stream().collect(Collectors.groupingBy(DeviceSpareType::getId));
map转list
List<String> mapKeyList = new ArrayList<String>(map.keySet());
List<String> mapValuesList = new ArrayList<String>(map.values());
map转set
Set<String> mapKeySet = map.keySet();
Set<String> mapValuesSet = new HashSet<String>(map.values());