Advertisement
sergAccount

Untitled

Mar 28th, 2021
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app21;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.stream.Collectors;
  11.  
  12. /**
  13.  *
  14.  * @author Admin
  15.  */
  16. public class Main5 {
  17.    
  18.     public static void main(String[] args) {
  19.         //
  20.         List<Person> list = new ArrayList<>();
  21.         list.add(new Person("name1", 11));
  22.         // вывод элементов стим - объектов типа Person      
  23.         list.stream().filter(p -> p.getName()!=null)
  24.                      .filter(p -> p.getAge()>10 && p.getAge()<20)
  25.                      .forEach(System.out::println);
  26.         //
  27.         List<Person> dst = list.stream().filter(p -> p.getName()!=null)
  28.                                         .filter(p -> p.getAge()>10 && p.getAge()<20).collect(Collectors.toList());
  29.         //
  30.         System.out.println("dst.list=" + dst.size());
  31.        
  32.     }    
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement