Title is sort of confusing but I'm not sure how to explain my problem in a simple sentence.
I have a homework task to group an arraylist of rectangles by length (same as perimeter in this case) using streams and collectors and to calculate minimum width for each group. I have tried the following:
public static Map<Double, Double> groupIndenticalPerimeterWidth(ArrayList<Rectangle> rectangles){
return rectangles.stream().collect(Collectors.groupingBy(Rectangle::getLength, Collectors.minBy((rectangle1, rectangle2) -> Double.compare(rectangle1.getWidth(), rectangle2.getWidth()))));
}
which gets me a Map<Double, Optional<Rectangle>> and I can't figure out how to get the width of minimum rectangle in the second arguement of Collectors.groupingBy instead of Optional<Rectangle>
Any help appreciated