Java 8 Lambda: Comparator

前端 未结 7 1448
鱼传尺愫
鱼传尺愫 2021-02-01 12:53

I want to sort a list with Lambda:

List messagesByDeviceType = new ArrayList();      
messagesByDeviceType.sort((Message o1, Messag         


        
7条回答
  •  [愿得一人]
    2021-02-01 13:24

    Comparator#compareTo returns an int; while getTime is obviously long.

    It would be nicer written like this:

     .sort(Comparator.comparingLong(Message::getTime))
    

提交回复
热议问题