Overriding equals for CopyOnWriteArraySet.add and remove

我们两清 提交于 2019-12-02 08:20:39

It is correct behavior it finds the element which is equal() so it removes first element

Removes the specified element from this set if it is present. More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.) ...

HashSet is the correct collection for my case. It won't call equals while adding elements unless there is hashCode match. That way I can still use my equals methods for my specific purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!