1.利用Collectors.toMap方法进行转换publicMapgetIdNameMap(Listaccounts){returnaccounts.stream().collect(Collectors.toMap(Account::getId,Account::getUsername));}其中第一个参数就是key,第二个参数就是value的值。2.收集对象实体本身在开发过程中我们也需要有时候对自己的list中的实体按照其中的一个字段进行分组(比如id->List),这时候要设置map的value值是实体本身。publicMapgetIdAccountMap(Listaccounts)