Java Comparator.comparing not comparing?

前端 未结 4 1466
遥遥无期
遥遥无期 2021-02-19 21:09

Following this question about sorting a list by another list, I tried to do the same thing - but from some reason it doesn\'t work for me. What am I missing?

            


        
4条回答
  •  没有蜡笔的小新
    2021-02-19 21:46

    The Comparator you are supplying calls indexOf for every num passed. The returned values are -1 on all calls, so the order is preserverd as-is.

    You need to sort natural.

    Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.

提交回复
热议问题