How could I do the following with Java Streams?
Let\'s say I have the following classes:
class Foo {
Bar b;
}
class Bar {
String id;
Str
An alternative is to support the equality contract on your key, Bar
:
class Bar {
String id;
String date;
public boolean equals(Object o){
if (o == null) return false;
if (!o.getClass().equals(getClass())) return false;
Bar other = (Bar)o;
return Objects.equals(o.id, id) && Objects.equals(o.date, date);
}
public int hashCode(){
return id.hashCode*31 + date.hashCode;
}
}
Now you can just have a Map
.