当前位置: 首页>后端>正文

Stream流案例

Stream流案例,第1张
Stream流案例,第2张
Stream流案例,第3张

package unit6;

import java.util.ArrayList;

import java.util.List;

public class Stream05 {

public static void main(String[] args) {

List<Employee> list = new ArrayList<>();

Employee ceo = new Employee("张三", 56, "男", 50000.42D, "浙江杭州", "浙江杭州", "ceo", null);

Employee manager1 = new Employee("李四", 47, "女", 20000.7D, "浙江宁波", "浙江宁波", "经理", ceo);

Employee manager2 = new Employee("王五", 45, "男", 24000.5D, "浙江金华", "浙江金华", "经理", ceo);

Employee employee1 = new Employee("麻六", 27, "女", 7000.6D, "浙江宁波", "广东广州", "售前", manager1);

Employee employee2 = new Employee("孙七", 28, "男", 8000.8D, "浙江宁波", "广东深圳", "售后", manager1);

Employee employee3 = new Employee("赵八", 27, "女", 9500.2D, "浙江杭州", "云南昆明", "售前", manager2);

Employee employee4 = new Employee("钱九", 26, "男", 9000.0D, "浙江杭州", "云南玉溪", "售后", manager2);

list.add(ceo);

list.add(manager1);

list.add(manager2);

list.add(employee1);

list.add(employee2);

list.add(employee3);

list.add(employee4);

// 综合案例

list.parallelStream()

.filter(e->e.getAge()>20 && e.getAge()<60)

.filter(e->e.getSalary()>5000)

.sorted((e1,e2) -> (int) (e2.getSalary() - e1.getSalary()))

.limit(3)

.map(e->e.getName()+e.getAge()+e.getSalary())

.forEach(System.out::println);

}

}


https://www.xamrdz.com/backend/3v91936090.html

相关文章: