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
标签:Collectors,toMap,Stream,stream,collect,getId,Person,方法 From: https://www.cnblogs.com/pxzbky/p/17280280.html