zoukankan      html  css  js  c++  java
  • Java8 stream常用方法归纳

    1.设置集合中全部元素的某一个属性的值

    Integer status = NoticeReadStatusEnum.READED.getCode();
                List<NoticeSendRecord> collect = noticeSendRecordList.stream().map(record -> {
                    record.setStatus(status);
                    return record;
                }).collect(Collectors.toList());

    // 示例 map
    public static void yy(){
    Student stu1 = new Student(18, "张三1","二班");
    Student stu2 = new Student(19, "张三2","二班");
    Student stu3 = new Student(15, "张三3","二班");
    Student stu4 = new Student(17, "张三4","二班");
    List<Student> list = Lists.newArrayList(stu1,stu2,stu3,stu4);
    List<Student> collect = list.stream().map(student -> {
    student.setAge(15);
    return student;
    }).collect(toList());
    System.out.println(collect.toString());
    }

    // 示例 peek
    public static void yy(){
    Student stu1 = new Student(18, "张三1","二班");
    Student stu2 = new Student(19, "张三2","二班");
    Student stu3 = new Student(15, "张三3","二班");
    Student stu4 = new Student(17, "张三4","二班");
    List<Student> list = Lists.newArrayList(stu1,stu2,stu3,stu4);
    List<Student> collect = list.stream().peek(student -> {
    student.setAge(15);
    student.setClassNmae("三班");
    }).collect(toList());
    System.out.println(collect.toString());
    }

      

  • 相关阅读:
    定制可引导的iso镜像
    镜像封装
    nginx知识及nginx集群搭建
    注册系统服务
    安装pip
    获取硬件信息
    查看网卡信息
    python paramiko模块
    python pexpect模块
    python-nmap的使用
  • 原文地址:https://www.cnblogs.com/tubashu/p/14949677.html
Copyright © 2011-2022 走看看