Advertisement
sergAccount

Untitled

Mar 28th, 2021
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 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.  
  10. /**
  11.  *
  12.  * @author Admin
  13.  */
  14. public class Main3 {
  15.    
  16.     public static void main(String[] args) {
  17.        
  18.         MyFilter filter1 = new MyFilter(2);
  19.         MyFilter filter2 = new MyFilter(3);
  20.        
  21.         ArrayList<String> list = new ArrayList<>();
  22.         list.add("ONE");
  23.         list.add("TWO");
  24.         list.add("TWO123");
  25.         list.add("O");
  26.         //
  27.         System.out.println("\nSAMPLE1:");
  28.         // filter1 - объект реализует интерфейс Predicate
  29.         list.stream().filter(filter1).forEach(x -> System.out.println(x));                
  30.         System.out.println("\nSAMPLE2:");
  31.         // filter1, filter2 - объект реализует интерфейс Predicate
  32.         list.stream().filter(filter1)
  33.                      .filter(filter2).forEach(x -> System.out.println(x));
  34.        
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement