java8 list转map

##List<T>转Map<S,T>code

Map<String,DemoEntity> map = stats.stream().collect(Collectors.toMap(DemoEntity::getKey,
                c -> c));

##List<T>转Map<S,T>(过滤重复key)ci

Map<String,DemoEntity> result = items.stream().collect(Collectors.toMap(DemoEntity::getKey,
                c -> c,(e1,e2) -> e1));

##List<T>转Map<S,S>get

Map<String,String> map = stats.stream().collect(Collectors.toMap(DemoEntity::getKey,
                DemoEntity::getStringValue));

##List<T>转Map<S,List<T>>it

Map<String,List<DemoEntity>> map = vars.stream().collect(Collectors.groupingBy(DemoEntity::getKey));

##docio

相关文章
相关标签/搜索