stream - to create a stream (a)

1, stream creation

@ 1, can be set by a collection stream series (serial), parallelStream (parallel) 
List <String> List = new new the ArrayList <String> ();
Stream<String> stream1 = list.stream();

// 2, stream created by a static manner Arrays in 
the Employee [] = Employee new new the Employee [ 10 ];
Stream<Employee> stream2 = Arrays.stream(employee);

// 3, Stream created by the static method 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, create entity classes

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
    }
}

 

Guess you like

Origin www.cnblogs.com/zhanh247/p/11854428.html