I am working on a framework where we are trying to convert our traditional loops to streams. My problem is I wrote two separate logics to get price and colors but I would like to merge both together so it will be presentable
Code to get the price values
List<Double> productPrices = product.getUpcs()
.stream()
.map(e -> e.getUpcDetails().getPrice().getRetail().getPriceValue())
.distinct()
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
Code to get the colors under prices
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")));
I harcoded price in the above section to obtain the colors, instead, i would like to get that as input from the list of price values and get an output in
Map<Double,List<colors>
output Map<75.4, {blue,black,orange}>
I tried merging these both without success, any help would be appriciated.
groupingBythat you need... since you need aMapas a resultdoubleto express money values. You’ll find loads of articles on the net about it…