Comparator and equals()

后端 未结 11 2029
终归单人心
终归单人心 2020-12-16 17:27

Suppose I need TreeSet with elements sorted with some domain logic. By this logic it doesn\'t matter order of some elements that doesn\'t equal so compare metho

11条回答
  •  生来不讨喜
    2020-12-16 17:59

    You have a Foo class wich is comparable but want to use a different sorting in a TreeSet structure. Then your idea is the correct way to do it. Use that constructor to "overrule" the natural sorting of Foo.

提交回复
热议问题