element cannot be mapped to a null key

问题描述:

使用jdk8的stream流分组报错

Map<String, List<UserInfoVo>> userInfoVoMap = userInfoVoList.stream().collect(Collectors.groupingBy(UserInfoVo::getTenantId));

原因分析:

分组字段的值不能为null


解决方案:

添加null判断

Map<String, List<UserInfoVo>> userInfoVoMap = userInfoVoList.stream()
			.filter(map->map.getTenantId()!=null)
			.collect(Collectors.groupingBy(UserInfoVo::getTenantId));
posted @ 2022-01-24 10:24  KeepArlen  阅读(821)  评论(0)    收藏  举报