小编roh*_*hit的帖子

Java流操作

我有一个对象,"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价格的价格值列表.

以上肯定不是我想要的.

java-8 java-stream

2
推荐指数
1
解决办法
74
查看次数

标签 统计

java-8 ×1

java-stream ×1