// Create a stream from a set of discrete values Stream<Integer> s1 = Stream.of(31,1,23,224,23,22)
// Create a stream from an array String names[] = {"Rod Jonson","Craig McClanahan","Gavin King"}; Stream<String> s = Stream.of(names); // using Stream.of()
// Create a stream from an array String names[] = {"Rod Johnson","Craig McClanahan","Gavin King"}; Stream<String> s = Arrays.stream(names);
ArrayList<String> names = new ArrayList<>(); names.add("Rod Johnson"); names.add("Craig McClanahan"); Stream<String> s = names.stream();
Path p = Paths.get("c:\\java\\names.txt"); Stream<String> s = Files.lines(p);
Stream<Integer> s = Stream.of(31,1,5,224,23,4); s = s.filter(n -> n > 10); s.forEach(System.out::println);
Stream.of(31,1,5,224,23,4) .filter(n -> n > 10) .forEach(System.out::println);
Path p = Paths.get("c:\\java\\names.txt"); Files.lines(p).sorted().forEach( System.out::println);
Path p = Paths.get("c:\\java\\names.txt"); int sum = Files.lines(p).mapToInt( s -> s.length()).sum(); System.out.println(sum);
ArrayList<Integer> hours = new ArrayList<>(); hours.add(10); hours.add(15); hours.add(20); Stream<MyTime> times = hours.stream().map( t -> new MyTime(t,0,0)); times.forEach( System.out::println);
Path p = Paths.get("c:\\java\\names.txt"); List<String> lines = Files.lines(p).filter( l -> l.length() > 15).collect( Collectors.toList()); for(String line : lines) { System.out.println(line); }
Path p = Paths.get("c:\\java\\names.txt"); List<String> lines = Files.readAllLines(p); // print lines that are more than 12 characters lines.parallelStream().filter( line -> line.length() > 12 ) .forEach(System.out::println);