|
Integer Streams
Author: Venkata Sudhakar
The below example shows how to create Integer Stream and print event numbers.
01 | package com.bethecoder.java8.streams; |
03 | import java.util.Arrays; |
04 | import java.util.stream.IntStream; |
05 | import java.util.stream.Stream; |
07 | public class StreamExample { |
09 | public static void main(String[] args) { |
11 | Stream<Integer> numberStream = Stream.of( 1 , 2 , 3 , 4 , 6 , 7 , 8 ); |
13 | .filter(n -> n % 2 == 0 ) |
14 | .forEach(System.out::println); |
17 | int [] numbers = new int [] { 1 , 2 , 3 , 4 , 6 , 7 , 8 }; |
18 | IntStream streamFromArray = Arrays.stream(numbers); |
20 | .filter(n -> n % 2 == 0 ) |
21 | .forEach(System.out::println); |
It gives the following output,
2
4
6
8
2
4
6
8
|
|