Compare objects in LinkedList.contains()

后端 未结 6 1736
梦谈多话
梦谈多话 2020-12-06 12:00

I want to be able to have LinkedList.contains() return true for a custom comparator.

Suppose that I have 1 LinkedList and 2 objects

LinkedList

        
6条回答
  •  孤城傲影
    2020-12-06 12:31

    LinkedList uses the equals method, not Comparable.compareTo. You should override equals (and hashCode) in MyObject to solve the problem.

提交回复
热议问题