Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.app6;
- import java.util.Arrays;
- import java.util.stream.DoubleStream;
- import java.util.stream.IntStream;
- public class Main {
- //
- public static void main(String[] args) {
- System.out.println("EX1:");
- int[] arr = new int[]{1, 2, 3};
- IntStream si = Arrays.stream(arr);
- si.forEach(x -> {System.out.println(x);}); // лябда-выражение в качестве параметра метода
- //
- System.out.println("EX2:");
- Arrays.stream(new int[]{1, 2, 3}).forEach(x -> {System.out.println(x);});
- // использование ссылки на метод - оператор ::
- System.out.println("EX3:");
- Arrays.stream(new int[]{1, 2, 3}).forEach(System.out::println); // System.out::println - ссылка на метод println
- //
- System.out.println("EX4:");
- DoubleStream si2 = Arrays.stream(new double[]{1.0, 2, 3});
- // filter
- si2.filter(x -> x>2).filter(x -> x>3).forEach(System.out::println);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement