java8中使⽤Lambda表达式将list中实体类的两个字段转Map
代码:
List<Entity> list = new ArrayList<>();
Map<Integer, String> map = list.stream().Map(Entity::getId, Entity::getType));
常⽤的lambda表达式:
**
* List -> Map
* 需要注意的是:
* toMap 如果集合对象有重复的key,会报错Duplicate key ....
*  apple1,apple12的id都为1。
*  可以⽤ (k1,k2)->k1 来设置,如果有重复的key,则保留key1,舍弃key2
*/
Map<Integer, Apple> appleMap = appleList.stream().Map(Apple::getId, a -> a,(k1,k2)->k1));
安照某⼀字段去重
list = list.stream().filter(distinctByKey(p -> ((ModCreditColumn) p).getFieldCode())).List());
List<Double> unitNetValue = listIncreaseDto.stream().map(IncreaseDto :: getUnitNetValue).List());
bigdecimal转换为integer//求和对象List
BigDecimal allFullMarketPrice = entityList.stream().filter(value -> FullMarketPrice()!= null).map(SceneAnalysisRespVo::getFullMarketPrice).reduce(BigDe
List<BigDecimal>  naturalDayList;
BigDecimal total = naturalDayList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
分组函数
Map<String, List<SceneAnalysisRespVo>> groupMap = GroupList().stream().upingBy(SceneAnalysisRespVo::getVmName));
//DV01之和
BigDecimal allDV01 = values.stream().filter(sceneAnalysisRespVo -> Dv() != null).map(SceneAnalysisRespVo::getDv).reduce(BigDecima