我有一个对象,"Item",带有字段:int:id String:price
字符串价格包含一个或多个以逗号分隔的价格值.
问题:使用流操作我要地图的类型,Map<Integer,Set<Integer>>从List<Item> items
其中Map的键是id,Set的值是从String价格中提取的整数.
列表中会有重复的ID,并且可以有不同的价格字符串.
我想出了一种产生以下结果的方法:
Map<Integer, Set<List<Integer>>> itemStoresMapIntermediate = items.stream()
.collect(Collectors.groupingBy(Item::getItemId,Collectors.mapping(Item::getStoresAsIntList, Collectors.toSet())));
Run Code Online (Sandbox Code Playgroud)
getStoresAsIntList()返回对象中String价格的价格值列表.
以上肯定不是我想要的.