Efficiently finding the intersection of a variable number of sets of strings

后端 未结 7 799
旧时难觅i
旧时难觅i 2020-11-27 06:14

I have a variable number of ArrayList\'s that I need to find the intersection of. A realistic cap on the number of sets of strings is probably around 35 but could be more. I

相关标签:
7条回答
  • 2020-11-27 06:57

    The best option would be to use HashSet to store the contents of these lists instead of ArrayList. If you can do that, you can create a temporary HashSet to which you add the elements to be intersected (use the putAll(..) method). Do tempSet.retainAll(storedSet) and tempSet will contain the intersection.

    0 讨论(0)
提交回复
热议问题