标签:filter code res bool div gets out org EDA
package com.xuweiwei.java8; import org.junit.Test; import java.util.Comparator; public class TestLambda { @Test public void test1(){ Comparator<Integer> comparator = new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return Integer.compare(01,02); } }; } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.Comparator; public class TestLambda { @Test public void test2(){ Comparator<Integer> comparator = (x,y) -> Integer.compare(x,y); } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.Comparator; public class TestLambda { @Test public void test2(){ Comparator<Integer> comparator = Integer::compare; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工年龄>35岁的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (employee.getAge() > 35) { result.add(employee); } } return result; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工薪水>5000的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (employee.getSalary() > 5000) { result.add(employee); } } return result; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; public interface MyPredicate<T> { boolean test(T t); }
package com.xuweiwei.java8; public class FilterEmployeeByAge implements MyPredicate<Employee> { @Override public boolean test(Employee employee) { return employee.getAge() > 35; } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees,new FilterEmployeeByAge()); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工年龄>35岁的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees,MyPredicate<Employee> myPredicate) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (myPredicate.test(employee)) { result.add(employee); } } return result; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; public interface MyPredicate<T> { boolean test(T t); }
package com.xuweiwei.java8; public class FilterEmployeeBySalary implements MyPredicate<Employee> { @Override public boolean test(Employee employee) { return employee.getSalary() > 5000; } }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees,new FilterEmployeeBySalary()); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工薪水>5000的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees,MyPredicate<Employee> myPredicate) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (myPredicate.test(employee)) { result.add(employee); } } return result; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; public interface MyPredicate<T> { boolean test(T t); }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees, new MyPredicate<Employee>() { @Override public boolean test(Employee employee) { return employee.getAge() > 35; } }); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工年龄>35岁的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees, MyPredicate<Employee> myPredicate) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (myPredicate.test(employee)) { result.add(employee); } } return result; } }
package com.xuweiwei.java8; public class Employee { private String name; private Integer age; private Double salary; public Employee() { } public Employee(String name, Integer age, Double salary) { this.name = name; this.age = age; this.salary = salary; } 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 Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } @Override public String toString() { return "Employee{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", salary=" + salary + ‘}‘; } }
package com.xuweiwei.java8; public interface MyPredicate<T> { boolean test(T t); }
package com.xuweiwei.java8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TestLambda { List<Employee> employees = Arrays.asList( new Employee("张三", 18, 9999.99), new Employee("李四", 38, 1111.11), new Employee("王五", 90, 5555.55), new Employee("赵六", 8, 3333.5), new Employee("田七", 16, 111.85), new Employee("王八", 45, 999.45) ); @Test public void test3() { List<Employee> employees = filterEmployees(this.employees, (e) -> e.getAge() > 35); for (Employee employee : employees) { System.out.println(employee); } } /** * 获取当前公司中员工年龄>35岁的员工信息 * * @param employees * @return */ public List<Employee> filterEmployees(List<Employee> employees, MyPredicate<Employee> myPredicate) { List<Employee> result = new ArrayList<>(); for (Employee employee : employees) { if (myPredicate.test(employee)) { result.add(employee); } } return result; } }
标签:filter code res bool div gets out org EDA
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9750273.html