Subtracting one arrayList from another arrayList

后端 未结 9 945
无人及你
无人及你 2021-01-01 11:00

I have two arrayLists and I am trying to \"subtract\" one arrayList from another. For example, if I have one arrayList [1,2,3] and I am trying to subtract [0, 2, 4] the resu

9条回答
  •  一个人的身影
    2021-01-01 11:52

    Traversing the minusArray using an index is one way to do this, but I suggest you make use of the contains(Object) method, which will allow you then to use remove(Object) for the particular element of array2.

    Of course, there's always the removeAll(Collection) which does pretty much everything you need...

提交回复
热议问题