我正在尝试将我们的传统循环转换为流的框架。我的问题是我写了两个独立的逻辑来获得价格和颜色,但我想合并这两个在一起,这将是像样形成地图问题的Java流
代码来获取价值
List<Double> productPrices = product.getUpcs()
.stream()
.map(e -> e.getUpcDetails().getPrice().getRetail().getPriceValue())
.distinct()
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
代码来获得下价格的颜色
product.getUpcs()
.stream()
.filter(e -> e.getUpcDetails().getPrice().getRetail().getPriceValue() == 74.5)
.flatMap(e -> e.getUpcDetails().getAttributes().stream())
.filter(e2 -> e2.getName().contentEquals("COLOR"))
.forEach(e3 -> System.out.println(e3.getValues().get(0).get("value")));
我harcoded价格在上面的部分,以获得颜色,相反,我想获得,作为从价格值列表输入和在
01得到的输出我试图合并这两个都没有成功,任何帮助将appriciated。
看起来像某种'groupingBy',你需要......因为你需要一个'Map'作为结果 – Eugene
作为一个附注,*从不*使用'double'来表示货币价值。你会在网上找到大量关于它的文章...... – Holger