码迷,mamicode.com
首页 > 其他好文 > 详细

stream

时间:2020-07-06 16:40:27      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:false   dsfa   oid   return   bsp   ring   inf   col   main   

public static void main(String[] args) {
        List<GoodsInfor> list = new ArrayList<>();
        List<GoodsInfor> list2 = new ArrayList<>();
        GoodsInfor p = new GoodsInfor();
        p.setGoodsId(1);
        p.setEachGoodsFare(1D);

        GoodsInfor p2 = new GoodsInfor();
        p2.setGoodsId(2);
        p2.setEachGoodsFare(2D);

        GoodsInfor p3 = new GoodsInfor();
        p3.setGoodsId(3);
        p3.setEachGoodsFare(3D);

        list.add(p);
        list.add(p2);
        list.add(p3);

        GoodsInfor p4 = new GoodsInfor();
        p4.setGoodsId(1);
        p4.setEachGoodsFare(0D);

        GoodsInfor p5 = new GoodsInfor();

        p5.setGoodsId(2);
        p5.setEachGoodsFare(0D);

        GoodsInfor p6 = new GoodsInfor();
        p6.setGoodsId(3);
        p6.setEachGoodsFare(0D);
        GoodsInfor p7 = new GoodsInfor();
        p7.setGoodsId(4);
        p7.setEachGoodsFare(0D);

        list2.add(p4);
        list2.add(p5);
        list2.add(p6);
        list2.add(p7);
//        list2.stream().flatMap(x -> list.stream()
//                .map(y -> {x.setEachGoodsFare(y.getEachGoodsFare());
//                        return x;
//                })
//        ).collect(Collectors.toList()).forEach(m->System.out.println(m));

        list2.stream().filter((x) -> list.stream().anyMatch((y)->
               {
                    if (x.getGoodsId() == y.getGoodsId()) {
                        x.setEachGoodsFare(y.getEachGoodsFare());
                        return true;
                    }
                   return false;
                })
        ).collect(Collectors.toList()).forEach(System.out::println);

    }

 

stream

标签:false   dsfa   oid   return   bsp   ring   inf   col   main   

原文地址:https://www.cnblogs.com/justuntil/p/13254998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!