java8 常用语法小结

// 判空

// 排序

 

//计数

long distinctCount = decreaseRequestList.stream().map(DecreaseRequest::getMemberSeq).distinct().count();

//映射

//对象list转属性list
List<ActivityDTO> activities = shopActivityTools.list(command, accountId);
List<String> codeList = activities.stream().map(e -> e.getCode()).collect(Collectors.toList());

//对象list转map
List<ActivityStrategyDTO> strategies = validateAndGet(activityServiceFacade.listStrategies(command, codes));
Map<String, ActivityStrategyDTO> codeEntityMap = strategies.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));

List<DecreaseRequest> decreaseRequestList = request.getRequests();
Map<Long, List<DecreaseRequest>> userDecreaseRequestMap = decreaseRequestList.stream().collect(Collectors.groupingBy(DecreaseRequest::getMemberSeq, Collectors.toList()));

//序列化

 

 

参考 https://blog.csdn.net/weixin_43496689/article/details/111631337

posted @ 2019-12-16 17:10  为爱奋斗不息  阅读(419)  评论(0编辑  收藏  举报