Also read : Convert ArrayList in Streams in java 8
Circuiting Operations in Streams in java 8
Reduce list to store it in Optional in java 8
Infinite Sequential ordered and unordered Stream - in java 8
1) Program/ Example - Create Stream of Integer in java 8
import java.util.stream.Stream;
/**
* Write Program to - Create Stream of Integer - in java 8
*/
public class CreateStreamOfIntegerExample {
public static void main(String[] args) {
System.out.println("1. Create Stream of Integer");
System.out.println("1.1 Create Stream of Integer using - of() method of Stream and passing the integers");
Stream<Integer> streamOfInteger = Stream.of(11, 12, 13);
System.out.println("1.2 Create Stream of Integer using - of() method of Stream and passing Integer array");
Stream<Integer> streamOfInteger2 = Stream.of(new Integer[]{11, 12, 13});
System.out.println("2. Display Stream of Integer");
streamOfInteger.forEach(System.out::println);
//Or
//streamOfInteger2.forEach(System.out::println);
}
}
/* OUTPUT
1. Create Stream of Integer
1.1 Create Stream of Integer using - of() method of Stream and passing the integers
1.2 Create Stream of Integer using - of() method of Stream and passing Integer array
2. Display Stream of Integer
11
12
13
*/
|
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.