tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java 8 Features > Stream API > Integer Streams

Integer Streams

Author: Venkata Sudhakar

The below example shows how to create Integer Stream and print event numbers.

01package com.bethecoder.java8.streams;
02 
03import java.util.Arrays;
04import java.util.stream.IntStream;
05import java.util.stream.Stream;
06 
07public class StreamExample {
08 
09    public static void main(String[] args) {
10 
11        Stream<Integer> numberStream = Stream.of(1, 2, 3, 4, 6, 7, 8);
12        numberStream
13            .filter(n -> n % 2 == 0)
14            .forEach(System.out::println);
15         
16         
17        int [] numbers = new int [] { 1, 2, 3, 4, 6, 7, 8 };
18        IntStream streamFromArray = Arrays.stream(numbers);
19        streamFromArray
20            .filter(n -> n % 2 == 0)
21            .forEach(System.out::println);
22         
23    }
24 
25}

It gives the following output,

2
4
6
8

2
4
6
8

 
  


  
bl  br