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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -