Getting object with max date property from list of objects Java 8

后端 未结 4 772
执念已碎
执念已碎 2021-02-01 01:23

I have a class called Contact that has a Date lastUpdated; variable.

I would like to pull the Contact out of a List

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 02:25

    Try the following (untested):

    contacts.stream().max(Comparator.comparing(Contact::getLastUpdated)).get()
    

提交回复
热议问题