Reputation: 415
Consider following object:
class Interval {
final String name;
final Date start;
final Date end;
final int intervalId;
}
I am provided with a list of intervals. I need to check it equals a given map. eg:
boolean checkEqual(List<Interval> intervals, Map<Date, Date> startEnd) {
}
i.e.
boolean checkEqual(List<Interval> intervals, Map<Date, Date> startEnd) {
Map<Date, Date> map = intervals.streams.filter ?? is there a way to do it ?
return map.equals(startEnd)
}
How to do it ?
Upvotes: 1
Views: 97
Reputation: 56489
use the toMap
collector:
Map<Date, Date> result = intervals.stream()
.collect(Collectors.toMap(Interval::getStartDate,
Interval::getEndDate));
Upvotes: 7