Arrays to Stream

suggest change

Converting an array of objects to Stream:

String[] arr = new String[] {"str1", "str2", "str3"};
Stream<String> stream = Arrays.stream(arr);

Converting an array of primitives to Stream using Arrays.stream() will transform the array to a primitive specialization of Stream:

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

You can also limit the Stream to a range of elements in the array. The start index is inclusive and the end index is exclusive:

int[] values = {1, 2, 3, 4};
IntStream intStream = Arrays.stream(values, 2, 4);

A method similar to Arrays.stream() appears in the Stream class: Stream.of(). The difference is that Stream.of() uses a varargs parameter, so you can write something like:

Stream<Integer> intStream = Stream.of(1, 2, 3);
Stream<String> stringStream = Stream.of("1", "2", "3");
Stream<Double> doubleStream = Stream.of(new Double[]{1.0, 2.0});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Arrays:
* Arrays
* Arrays to Stream

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap