sergAccount

Untitled

Jan 30th, 2021
433
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 doSomething(int value){
  15.         System.out.println("doSomething=" + value);
  16.     }
  17.     //
  18.     public static void main(String[] args) {
  19.        
  20.         System.out.println("EX1:");
  21.         int[] arr = new int[]{1, 2, 3};
  22.         IntStream si = Arrays.stream(arr);
  23.         si.forEach(x -> {System.out.println(x);}); // лябда-выражение в качестве параметра метода
  24.         //
  25.         System.out.println("EX2:");
  26.         Arrays.stream(new int[]{1, 2, 3}).forEach(x -> {System.out.println(x);});        
  27.         // использование ссылки на метод - оператор ::
  28.         System.out.println("EX3:");
  29.         Arrays.stream(new int[]{1, 2, 3}).forEach(System.out::println); // System.out::println - ссылка на метод println
  30.         //
  31.         System.out.println("EX4:");
  32.         DoubleStream si2 = Arrays.stream(new double[]{1.0, 2, 3});
  33.         // filter
  34.         si2.filter(x -> x>2).filter(x -> x>3).forEach(System.out::println);
  35.         System.out.println("EX5:");
  36.         Arrays.stream(new int[]{1, 2, 3}).forEach(Main::doSomething);
  37.  
  38.        
  39.     }
  40. }
  41.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×