How can I sort a list of maps by value of some specific key using Java 8?

前端 未结 6 2220
情话喂你
情话喂你 2020-12-18 02:46

How can I sort a List of Map using Java 8? The map contains a key called last_name, and the value associated wit

6条回答
  •  独厮守ぢ
    2020-12-18 03:06

    It looks like you can rewrite your code like

    peopleList.sort(Comparator.comparing(
                        m -> m.get("yourKey"), 
                        Comparator.nullsLast(Comparator.naturalOrder()))
                   )
    

提交回复
热议问题