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.app21;
- import java.util.ArrayList;
- import java.util.stream.Stream;
- /**
- *
- * @author Admin
- */
- public class Main2 {
- //
- public static void main(String[] args) {
- ArrayList<String> list = new ArrayList<>();
- list.add("ONE");
- list.add("TWO");
- // forEach
- Stream<String> s = list.stream();
- // используем лямбда выражение для вывода элементов потока на экран
- s.forEach(x -> System.out.println(x));
- //
- list.stream().forEach(x -> System.out.println(x));
- // используем метод filter
- System.out.println("\nFILTER:");
- list.stream().filter(x -> x.startsWith("ONE")).forEach(x -> System.out.println(x));
- System.out.println("\nFILTER2:");
- // цепочка фильтров
- list.stream().filter(x -> x.startsWith("ONE"))
- .filter(x -> x.startsWith("ONE")).forEach(x -> System.out.println(x));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement