java - How to compare two Lists of objetcs for difference in objects fields? -
collegues, have 2 lists of different objects.
list<sharesentity> mainsystemsecurities; list<secureentity> supportsystemsecurities;
objects sharesentity
, secureentity
have 1 same fiels isin. in case isins same in object of theese collections, in cases there different isins in supportsystemsecurities
, mainsystemsecurities
collection's objects.
i need understand objects (better tell isins) supportsystemsecurities
list absence in mainsystemsecurities
.
how it? better way compare 2 collection (to compare filedls of collection's objects)?
build map<isintype, sharesentity>
first list:
map<isintype, sharesentity> sharesentitymap = mainsystemsecurities.stream().collect( collectors.tomap(sharesentity::getisin, functions.identity()));
then can iterate other list, looking entities first list in map:
for (secureentity secureentity : supportsystemsecurities) { sharesentity correspondingsharesentity = sharesentitymap.get(secureentity.getisin()); // ... }
this assumes there single item per isin in first list. if that's not case, can build map<isintype, list<sharesentity>>
instead, , proceed (or use multimap
).
Comments
Post a Comment