JDK8 Stream操作整理
1,forEach
this.quoteItemList.forEach(p -> p.setMode(mode));
2,获取对话属性,去重后生成集合
List<String> projects = this.quoteItemList.stream().map(p -> p.getVersion()).distinct().collect(Collectors.toList());
3,过滤后汇总
double totalRealManDay = this.quoteItemList.stream().filter(p -> p.getAssignee().equals(person.getName())).mapToDouble(p -> p.getSpend()).sum() ;
sum可以改成count等其它函数
4,排序号取第一个
ProfitResult monthResult = calcResult.stream().sorted(Comparable::compareTo).filter(p -> p.getPeriod().equals(period)).findAny().get();
if (monthResult != null) {
}
5,分组统计转成Map
Map<String, Double> monthMap = this.data.stream().filter(p -> p.getVersion().equals(project)).collect(
Collectors.groupingBy(QuoteItem::getFinishMonth, Collectors.summingDouble(QuoteItem::getEstimate))
);
6,分页获取
//取出一页数据的id列表
List<String> ids = list.stream().skip((findDoctorVo.getPage() -1) * findDoctorVo.getPagesize())
.limit(findDoctorVo.getPagesize())
.map(TeamVo::getTeamId)
.collect(Collectors.toList());
7,转换成其它对象
方式一:
List<SessionListVo> newList = list.stream().map(SessionListVo::new).collect(Collectors.toList());
方式二:
List<SellInfo> saleList = list.stream().filter(p->p.saleValid()).map(info->{
SellInfo item = new SellInfo();
item.setProductName(info.getGoodsname());
return item;
}).collect(Collectors.toList());
8,查询并拼接
String newTags = tags.stream().filter((p) -> !p.equals(this.defaultTag)).collect(Collectors.joining(this.SPLITER));
JDK8 Stream操作整理的更多相关文章
- 【Java】【6】JDK8 Stream操作整理
摘要: 1,List<EntityOld>转换为List<EntityNew> List<EntityOld> list = oldList; List<En ...
- 大型网站技术架构(四)--核心架构要素 开启mac上印象笔记的代码块 大型网站技术架构(三)--架构模式 JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)
大型网站技术架构(四)--核心架构要素 作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载.此篇已收录至<大型网站技 ...
- JDK8 Stream 数据流效率分析
JDK8 Stream 数据流效率分析 Stream 是Java SE 8类库中新增的关键抽象,它被定义于 java.util.stream (这个包里有若干流类型: Stream<T> ...
- SQL不同服务器数据库之间的数据操作整理(完整版)
---------------------------------------------------------------------------------- -- Author : htl25 ...
- 转载-SQL不同服务器数据库之间的数据操作整理(完整版) .
---------------------------------------------------------------------------------- -- Author : htl25 ...
- c#常见stream操作
原文: c#常见stream操作 常见并常用的stream一共有 文件流(FileStream), 内存流(MemoryStream), 压缩流(GZipStream), 加密流(CrypToStre ...
- javascript中字符串常用操作整理
javascript中字符串常用操作整理 字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用 ...
- java8 Stream操作
Stream操作详解:https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/#icomments
- SVG.js 元素操作整理(二)-Transform
一.transform()获取或设置矩阵变换 var draw = SVG('svg1').size(300, 300); //Transforming SVG元素矩阵变换 var rect = dr ...
随机推荐
- SpringBoot系列三:SpringBoot自定义Starter
在前面两章 SpringBoot入门 .SpringBoot自动配置原理 的学习后,我们对如何创建一个 SpringBoot 项目.SpringBoot 的运行原理以及自动配置等都有了一定的了解.如果 ...
- 基于Spring Boot框架开发的一个Mock
背景:在项目后端接口开发还未完成,我们无法进行自动化接口用例的调试,希望与开发同步完成接口自动化用例的编写及调试,待项目转测后,可以直接跑自动化用例,提高测试效率. 选用的maven + Spring ...
- Linux--奇思淫才
根据进程号找到可执行的文件路径 [ec2-user@baolin ~]$ ll /proc/<pid>/exe lrwxrwxrwx 1 ec2-user ec2-user 0 May 3 ...
- android studio——替换全局的某个字符串
android studio——替换全局的某个字符串 edit - > replace in path https://blog.csdn.net/dragon0103/article/deta ...
- thinkphp5图片上传接口
public function avatarUpload() { $file = request()->file('file'); $filePath = 'avatar'; $width = ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-12基于cookie登录授权认证并实现前台会员、后台管理员同时登录
1.登录的实现 登录功能实现起来有哪些常用的方式,大家首先想到的肯定是cookie或session或cookie+session,当然还有其他模式,今天主要探讨一下在Asp.net core 2.0下 ...
- BigDecimal类型转换
djjfbr.setMoney(new BigDecimal(djjfbillrecord.getMoney()));
- (二)文档请求不同源之location.hash跨域
一.基本原理 用location.hash解决域名完全不同的跨域,例如,http://www.baidu.com#helloworld中的"#helloworld"就是locati ...
- ApiKernel
using System; using System.Runtime.InteropServices; using System.Text; using HANDLE = System.IntPtr; ...
- ASP.NET Core 2.2 迁移至 3.0 备忘录
将 ASP.NET Core 2.2 迁移至 ASP.NET Core 3.0 需要注意的地方记录在这篇随笔中. TargetFramework 改为 netcoreapp3.0 <Target ...