I have a stream of Event
s
public class Event {
Location location;
double turnout;
//... other fields & getters
}
And a statistics class EventStatistics
public class EventStatistics {
// Stats properties e.g. turnout standard deviation/median
public EventStatistics(List<Event> events) {
// Generate stats
}
}
I need to group all the events by location & create a map of location and event statistics Map<Location, EventStatistics>
The group by is just:
Map<Location, List<Event>> byLocation = events.stream().collect(groupingBy(Event::getLocation));
I know there is an overloaded groupingBy(function, collector)
collector. Can I use somehow this to generate my Map<Location, EventStatistics>
in a single stream?
ArrayList::new
doesn't infer the Event type. I need to specifyArrayList<Event>::new
. – Wailful