Stream 式方法

发布时间 2023-04-02 12:56:55作者: 求索哲

 

 

 

 

 

Map<Integer, Person> collect = list.stream().collect(Collectors.toMap(Person::getId, Function.identity()));
Map<Integer, Person> collect1 = list.stream().collect(Collectors.toMap(Person::getId, Function.identity(), (a,b)->a));
Map<Integer, Person> collect2 = list.stream().collect(Collectors.toMap(Person::getId, v -> v, (a,b)->a));
Collection<Person> values = list.stream().collect(Collectors.toMap(Person::getId, Function.identity(), (a, b) -> a)).values();
Map<Integer, String> maps = list.stream().collect(Collectors.toMap(Person::getId, Person::getName, (key1, key2) -> key2));

   {3=Person(Id=3, name=王五)}
   {3=Person(Id=3, name=王五)}
   {3=Person(Id=3, name=王五)}
   [Person(Id=3, name=王五)]
  1