Advertisement
sergAccount

Untitled

Jan 30th, 2021
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 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.app6;
  7.  
  8. import java.util.Arrays;
  9. import java.util.stream.DoubleStream;
  10. import java.util.stream.IntStream;
  11.  
  12. public class Main {
  13.     //
  14.     public static void main(String[] args) {
  15.        
  16.         System.out.println("EX1:");
  17.         int[] arr = new int[]{1, 2, 3};
  18.         IntStream si = Arrays.stream(arr);
  19.         si.forEach(x -> {System.out.println(x);}); // лябда-выражение в качестве параметра метода
  20.         //
  21.         System.out.println("EX2:");
  22.         Arrays.stream(new int[]{1, 2, 3}).forEach(x -> {System.out.println(x);});        
  23.         // использование ссылки на метод - оператор ::
  24.         System.out.println("EX3:");
  25.         Arrays.stream(new int[]{1, 2, 3}).forEach(System.out::println); // System.out::println - ссылка на метод println
  26.         //
  27.         System.out.println("EX4:");
  28.         DoubleStream si2 = Arrays.stream(new double[]{1.0, 2, 3});
  29.         // filter
  30.         si2.filter(x -> x>2).filter(x -> x>3).forEach(System.out::println);
  31.        
  32.  
  33.        
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement