Java stream - Sort a List to a HashMap of Lists

后端 未结 2 1700
隐瞒了意图╮
隐瞒了意图╮ 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 02:55

    The great answer above can further be improved by method reference notation:

    List dogs = ...
    Map> map = dogs.stream()
         .collect(Collectors.groupingBy(Dog::getBreed)); 
    

提交回复
热议问题