- List<String> list = Lists.newArrayList(“1”, “2”, “3”, “1”);
- Map<String, List<String>> map = list.stream().collect(Collectors.toMap(key -> key,
- value -> Lists.newArrayList(value),
- (List<String> newValueList, List<String> oldValueList) -> {
- oldValueList.addAll(newValueList);
- return oldValueList;
- }));
- System.out.println(JSON.toJSONString(map));
- Map<String,List<Parts>> partsMap = partList.stream().collect(Collectors.toMap(Parts::getMaintainCode, part ->
- Lists.newArrayList(part),(List<Parts> newValueList,List<Parts> oldValueList)->
- {oldValueList.addAll(newValueList);
- return oldValueList;
- }));