Java stream - Sort a List to a HashMap of Lists

后端 未结 2 1696
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 02:14

Let\'s say I have a Dog class.

Inside it I have a Map and one of the values is Breed.

public         


        
2条回答
  •  隐瞒了意图╮
    2021-01-31 03:03

    You can do it with groupingBy.

    Assuming that your input is a List, the Map member inside the Dog class is called map, and the Breed is stored for the "Breed" key :

    List dogs = ...
    Map> map = dogs.stream()
         .collect(Collectors.groupingBy(d -> d.map.get("Breed")));
    

提交回复
热议问题