Convert Array to Stream Using Java 8


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Object and Primitive Arrays

This Java template lets you get started quickly with a simple one-page playground.

// {...}
//Object Array
String[] array = {"t", "e", "c", "h", "i", "o"};
Stream<String> stream1 =;
stream1.forEach(x -> System.out.println(x));
Stream<String> stream2 = Stream.of(array);
stream2.forEach(x -> System.out.println(x));
//Premitive Array
int[] intArray = {1, 2, 3, 4, 5};
IntStream intStream1 =;
intStream1.forEach(x -> System.out.println(x));
Stream<int[]> tempStream = Stream.of(intArray);
IntStream intStream2 = tempStream.flatMapToInt(x ->;
intStream2.forEach(x -> System.out.println(x));

Advanced usage

If you want a more complex example (external libraries, viewers...), use the Advanced Java template

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content