ArrayList removeAll() not removing objects

前端 未结 3 782
梦谈多话
梦谈多话 2020-12-10 17:28

I have the simple ArrayLists of the member class:

ArrayList mGroupMembers = new ArrayList<>();
ArrayList mFriends = new Arr         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 17:52

    You have to know that

    ArrayList#removeAll(Collection)

    makes a call to

    ArrayList#contains(Object)

    which makes a call to

    ArrayList#indexOf(Object)

    which finally calls

    Object#equals


    So if equals is not correctly overridden (following the equals contract rules), you're not getting the correct behaviour.

提交回复
热议问题