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
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值