java - How do find identical pairs in Collection? -
if have collection of set. , must find identical pairs in collection, i.e.:
collection:
- set {object_a, object_b, object_c}
 - set {object_a, object_b, object_f}
 
how find pair: object_a-object_b in collection> ??? java library can used purpose?
if want use lib, use google guava, , invoke:
sets.intersection(setone, settwo);   see sets.intersection().
for instance:
sets.setview<string> intersectionview = sets.intersection(     immutableset.of("object_a", "object_b", "object_c"),     immutableset.of("object_a", "object_b", "object_d")); set<string> intersectionset = intersectionview.immutablecopy();   intersectionview view "object_a" , "object_b" elements, backed both original sets. intersectionset immutable set of intersection.
refer guava docs more details , alternatives based on needs (mutability, etc...).
Comments
Post a Comment