使用java8 api方法list.stream().map().collect(Collectors.toList())

今天做了第一个任务通过querydsl实现处方实绩的一个日期日次周次月次的取数据功能

  1. 实现类型转换
List<PrescriptionVO> productResultDTOToVO = productResult.getResults().stream().map(dto -> new PrescriptionVO())
                .collect(Collectors.toList());

        QueryResults<PrescriptionVO> r = new QueryResults<>(
                productResultDTOToVO,
                productResult.getLimit(),
                productResult.getOffset(),
                productResult.getTotal()
        );
        results = r;*/
        //return results == null ? new QueryResults<>(new ArrayList<>(), 0L, 0L, 0L) : results;

简单来说就是通过.stream().map(自定义名称 -> new 要转换的类名()).collect(Collectors.toList());

  1. .collect:结束Stream流。
  2. Collectors.toList():类实现了很多归约操作,例如将流转换成集合和聚合元素。Collectors 可用于返回列表或字符串
  3. steam():把一个源数据,可以是集合,数组,I/O channel, 产生器generator 等,转化成流。
  4. map():用于映射每个元素到对应的结果。以下代码片段使用 map 输出了元素对应的平方数:
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值