In addition to my question asked previously, that can be found here, How to combine list elements and find the price of largest combination
Instead of using Integer price
, I am using String price
,
List<Long> highest = details
.stream()
.map(d -> Stream.concat(Stream.of(d.getDetailId()), d.getStackableDetails().stream()).collect(Collectors.toList()))
.collect(Collectors.toMap(s -> s.stream().map(Double.class::cast).reduce(0D,
(left, right) -> left + Double.parseDouble(map.get(right).getPrice())),
s -> s.stream().collect(Collectors.toList()),
(left, right) -> right,
TreeMap::new))
.lastEntry().getValue();
But I keep getting a class cast exception while running the same. Can someone tell me why I'm not able to cast the Stream type and how I can rectify the same. Thanks!