I am pretty new to Lambdas and I'm trying to use it the following way, but it doesn't seem to work. Is it possible to have multiple declarations where ONE of those is the condition?
ArrayList<Message> msgs = new ArrayList<>(ms.values());
Calendar cal = Calendar.getInstance();
msgs.stream().filter( m -> {
cal.setTime(m.getCreated());
cal.get(Calendar.YEAR) == year
});
I understand that it works like:
collection.stream().filter(x -> 1 == x);
But since I need to set the Date
and use it with Calendar
to get the year, I would have to do this in two declarations.
I know this works:
msgs.forEach(m -> {
cal.setTime(m.getCreated());
if (cal.get(Calendar.YEAR) != year) {
msgs.remove(m);
}
});
But I want to know if it is possible to do it the way I'm trying to, or something relatively similar?