Java Comparator.comparing not comparing?

前端 未结 4 1023
遥遥无期
遥遥无期 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:44

    You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.

提交回复
热议问题