Streams from Arrays

Description

java.util.Arrays class contains stream() method to create sequential streams from arrays.

We can use it to create an IntStream, a LongStream, a DoubleStream, and a Stream<T>.

Example

The following code creates an IntStream.

IntStream numbers = Arrays.stream(new int[]{1, 2, 3});

The following code creates a Stream<String> from an int array and a String array.


Stream<String> names = Arrays.stream(new String[] {"XML",   "Java"});




















Home »
  Java Streams »
    Tutorial »




Java Streams Tutorial