Intersection and union of ArrayLists in Java

后端 未结 24 2505
离开以前
离开以前 2020-11-22 06:05

Are there any methods to do so? I was looking but couldn\'t find any.

Another question: I need these methods so I can filter files. Some are AND filter

24条回答
  •  温柔的废话
    2020-11-22 06:55

    • retainAll will modify your list
    • Guava doesn't have APIs for List (only for set)

    I found ListUtils very useful for this use case.

    Use ListUtils from org.apache.commons.collections if you do not want to modify existing list.

    ListUtils.intersection(list1, list2)

提交回复
热议问题