zoukankan      html  css  js  c++  java
  • Java8 stream基础

    List<Integer> list = new ArrayList<Integer>();
    list.add(2);
    list.add(4);
    list.add(0);
    list.add(100);
    System.out.println("----------------stream---------------------");
    list.stream().filter(e -> e > 4).forEach(System.out::println);
    Stream<Integer> list1 = list.stream().filter(e -> e > 0);
    Iterator<Integer> iter = list1.iterator();
    while (iter.hasNext()) {
    System.out.println(iter.next());
    }
    System.out.println("--------------filter 条件查询--------------------");
    list = list.stream().filter(e -> e > 2).collect(Collectors.toList());
    list.forEach(System.out::println);
    List<Student> studentlist=new ArrayList<Student>();
    studentlist.add(new Student("A",12));
    studentlist.add(new Student("B",5));
    studentlist.add(new Student("C",16));
    studentlist.add(new Student("D",2));
    System.out.println("取出集合中对象指定属性");
    studentlist.stream().map(Student::getName).forEach(System.out::println);
    System.out.println("-----------------------------按对象属性正序---------------------------------------------");
    studentlist.stream().sorted(Comparator.comparing(Student::getAge)).forEach(System.out::println);
    System.out.println("-----------------------------按对象属性倒序---------------------------------------------");
    studentlist.stream().sorted(Comparator.comparing(Student::getAge).reversed()).forEach(System.out::println);
    studentlist=studentlist.stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());
    System.out.println("----------------------------stream 转化为集合输出----------------------------------------------");
    studentlist.forEach(System.out::print);

    class Student{
    private String name;
    private Integer age;
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public Integer getAge() {
    return age;
    }
    public void setAge(Integer age) {
    this.age = age;
    }
    public Student(String name, Integer age) {
    super();
    this.name = name;
    this.age = age;
    }
    public Student() {
    super();
    }
    @Override
    public String toString() {
    return "Student [name=" + name + ", age=" + age + "]";
    }


    }

  • 相关阅读:
    Linux XOR.DDoS样本取证特征与清除
    利用Volatility对Linux内存取证分析-常用命令翻译
    【黑客免杀攻防】读书笔记14
    CertUtil.exe被利用来下载恶意软件
    利用rundll32执行程序的函数执行程序
    揭秘Patchwork APT攻击-恶意软件样本BADNEWS
    【CTF MISC】pyc文件反编译到Python源码-2017世安杯CTF writeup详解
    [ 总结 ] 删除通过find查找到的文件
    [ 脚本 ] RHEL6.x 及Centos6.x 初始化脚本
    [ 手记 ] 联想rd650服务器整列及系统安装
  • 原文地址:https://www.cnblogs.com/coderdxj/p/9020006.html
Copyright © 2011-2022 走看看