list 类型转换 Map

/**
* list 类型转换
*
* @param list source
* @param keyMapper keyMapper
* @param <T> T
* @param <K> K
* @return Map
*/
public static <T, K> Map<K, List<T>> groupBy(List<T> list, Function<T, K> keyMapper) {
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyMap();
}
return list.stream().collect(Collectors.groupingBy(keyMapper));
}
posted @ 2024-02-20 11:22  setevn  阅读(5)  评论(0编辑  收藏  举报