1.key和value都是list里面对象得属性
public Map getIdNameMap(List accounts) {
return accounts.stream().collect(Collectors.toMap(Account::getId, Account::getUsername));
}
2.key为属性value为对象本身
public Map getIdAccountMap(List accounts) {
return accounts.stream().collect(Collectors.toMap(Account::getId, account -> account));
}