1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| @Test public void test1(){
List<Employee> list = EmployeeData.getEmployees(); Stream<Employee> stream = list.stream(); stream.filter(emp -> emp.getSalary()>7000).forEach(System.out::println);
list.stream().limit(4).forEach(System.out::println);
list.stream().skip(5).forEach(System.out::println);
list.stream().distinct().forEach(System.out::println); }
@Test public void test2(){ List<String> list = Arrays.aslist("aa","bb","cc","dd"); list.stream().map(str -> str.toUpperCase()).forEach(System.out::println);
List<Employee> employees = EmployeeData.getEmployees(); employees.stream().filter(emp->emp.getName().length()>3).forEach(System.out::println);
List<Employee> employees = EmployeeData.getEmployees(); employees.stream().filter(emp->emp.getName().length()>3).map(emp->emp.getName()).forEach(System.out::println); }
@Test public void test3(){ Integer[] arr = new Integer[]{12,3,4,5,6,23,45,1}; String[] arr1 = new String[]{"GG","DD","FF","SS","JJ"}; Arrays.stream(arr).sorted().forEach(System.out::println);
List<Employee> list = EmployeeData.getEmployees(); list.stream().sorted((e1,e2)-> e1.getAge() - e2.getAge()).forEach(System.out::println);
}
|