I have list of Objects say
class Address {
private String houseno;
private String street;
private String city;
private String landmark;
private String country;
}
class Obj1 {
private String id;
private String name;
private String mail;
private List<Address> address;
}
List<Obj1> obj1s = new ArrayList<>();
I have list of obj1s filled with data where I need to extract it with some filters. I need to retrieve all the obj1s where city and country must not be duplicate. If either of the address list contains same city and country which is same in other obj1, then I don't need in that list.
I am trying the same but not working.
obj1s.stream().collect(Collectors.toMap((obj1.getAddress()), p -> p, (p, q) -> p)).values();
It can be done with loops and if else conditions, but looking for java streams and betters solutions. Is there any good way to solve this?
city+country can be duplicate across all obj1s. In address list, it will be unique
Obj1s inobj1s, or across all addresses in theObj1object?Obj1toUser. Doubt: If forObj1 aandObj1 bany of theirAddresshas same city+country, you don't want these two to be a part of final result?