zoukankan      html  css  js  c++  java
  • stream — 创建stream(一)

    1、stream创建

    // 1、可以通过collection系列集合 stream(串行)、parallelStream(并行)
    List<String> list = new ArrayList<String>();
    Stream<String> stream1 = list.stream();
    
    // 2、通过Arrays中的静态stream方式创建
    Employee[] employee = new Employee[10];
    Stream<Employee> stream2 = Arrays.stream(employee);
    
    // 3、通过Stream中的静态方法of创建
    Stream<String> stream3 = Stream.of("aa", "bb", "cc", "dd");
    
    // 4、迭代
    Stream<Integer> iterate = Stream.iterate(10, (x) -> x + 2);
    iterate.limit(10).forEach(System.out::println);
    // 5、生成
    Stream.generate(() -> Math.random()).limit(10).forEach(System.out::println);

     2、创建实体类

    package com.zh.stream;
    
    import java.util.Date;
    
    public class Employee {
    
        private Integer age;
        private String name;
        private double salary;
        private Status status;
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public double getSalary() {
            return salary;
        }
    
        public void setSalary(double salary) {
            this.salary = salary;
        }
    
        public Status getStatus() {
            return status;
        }
    
        public void setStatus(Status status) {
            this.status = status;
        }
    
        public Employee() {
    
        }
    
        public Employee(Integer age) {
            this.age = age;
        }
    
        public Employee(Integer age, String name) {
            this.age = age;
            this.name = name;
        }
    
        public Employee(Integer age, String name, double salary) {
            this.age = age;
            this.name = name;
            this.salary = salary;
        }
    
        public Employee(Integer id, Date createTime, Date updateTime, Integer age, String name, double salary,
                Status status) {
            this.age = age;
            this.name = name;
            this.salary = salary;
            this.status = status;
        }
    
        public Employee(Integer age, String name, double salary, Status status) {
            this.age = age;
            this.name = name;
            this.salary = salary;
            this.status = status;
        }
    
        @Override
        public String toString() {
            return "Employee [age=" + age + ", name=" + name + ", salary=" + salary + ", status=" + status + "]";
        }
    
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((age == null) ? 0 : age.hashCode());
            result = prime * result + ((name == null) ? 0 : name.hashCode());
            long temp;
            temp = Double.doubleToLongBits(salary);
            result = prime * result + (int) (temp ^ (temp >>> 32));
            return result;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Employee other = (Employee) obj;
            if (age == null) {
                if (other.age != null)
                    return false;
            } else if (!age.equals(other.age))
                return false;
            if (name == null) {
                if (other.name != null)
                    return false;
            } else if (!name.equals(other.name))
                return false;
            if (Double.doubleToLongBits(salary) != Double.doubleToLongBits(other.salary))
                return false;
            return true;
        }
    
        public enum Status {
            FREE, BUSY, VOCATION
        }
    }
  • 相关阅读:
    文档的几何形状和滚动
    聊聊并发——生产者消费者模式
    在JavaScript中什么时候使用==是正确的?
    HTML5使用canvas画图时,图片被自动放大模糊的问题
    获取元素的几种方式
    利用jQuery和CSS实现环形进度条
    最实用、最常用的jQuery代码片段
    表格样式
    javascript常量的定义
    null 和 undefined 的区别
  • 原文地址:https://www.cnblogs.com/zhanh247/p/11854428.html
Copyright © 2011-2022 走看看