Intersection and union of ArrayLists in Java

后端 未结 24 2677
离开以前
离开以前 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:47

    list1.retainAll(list2) - is intersection
    

    union will be removeAll and then addAll.

    Find more in the documentation of collection(ArrayList is a collection) http://download.oracle.com/javase/1.5.0/docs/api/java/util/Collection.html

提交回复
热议问题