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

后端 未结 7 839
旧时难觅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:32

    Set.retainAll() is how you find the intersection of two sets. If you use HashSet, then converting your ArrayLists to Sets and using retainAll() in a loop over all of them is actually O(n).

提交回复
热议问题