/* * 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 streams; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Stream; /** * * @author Admin */ public class Streams { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Stream words = Stream.of("one","word", "next","Word"); words.forEach(value-> System.out.println(value)); List list = new ArrayList<>(); Collections.addAll(list, 1, 5, 6, 11, 3, 15, 7, 8); list.stream() .forEach(value-> System.out.println(value)); // Stream echo =Stream.generate(() -> "Echo"); // echo.forEach(System.out::println); // Stream randoms =Stream.generate(Math::random); // randoms.forEach(System.out::println); // Stream integers = Stream.iterate( // BigInteger.ZERO, n -> n.add(BigInteger.ONE)); // integers.forEach(System.out::println); //BigInteger limit = new BigInteger("100000"); //Stream integers = Stream.iterate( // BigInteger.ZERO, // n -> n.compareTo(limit)<0, // n -> n.add(BigInteger.ONE)); //integers.forEach(System.out::println); Stream.iterate(LocalDate.now(), ld->ld.plusDays(1L)) .limit(10) .forEach(System.out::println); String str = "asd r f t 3 4455 jkljk &jlkjl(((( 0000"; String regex = "\\PL+";// “\\PL+” строку на слова Stream words1 = Pattern.compile(regex) . splitAsStream(str); words1.forEach(System.out::println); try( Stream lines = Files.lines(Paths.get("alice30.txt"))){ lines.forEach(System.out::println); } catch (IOException ex) { System.out.println("file not found"); } List words2 = new ArrayList<>(); Collections.addAll (words2, "ASDFG","1aHse","kdjlGJHGf"); Stream lowercaseW = words2.stream() .map(String::toLowerCase); lowercaseW.forEach(System.out::println); Stream.of("d2", "a2", "b1", "b3", "c") .filter(s -> { System.out.println("filter: " + s); return true; }) .forEach(s -> System.out.println("forEach: " + s)); } }