Java Collections Java Java API
Class:
java.util.Arrays
Methods:
These methods return a corresponding sequential streams defined in java.util.stream.*.
public static <T> Stream<T> stream(T[] array)
public static <T> Stream<T> stream(T[] array,
int startInclusive,
int endExclusive)
public static IntStream stream(int[] array)
public static IntStream stream(int[] array,
int startInclusive,
int endExclusive)
public static LongStream stream(long[] array)
public static LongStream stream(long[] array,
int startInclusive,
int endExclusive)
public static DoubleStream stream(double[] array)
public static DoubleStream stream(double[] array,
int startInclusive,
int endExclusive)
Examples
package com.logicbig.example.arrays;
import java.util.Arrays; import java.util.stream.IntStream;
public class StreamExample {
public static void main(String... args) { int[] arr = {1, 2, 3, 4, 5}; IntStream stream = Arrays.stream(arr); stream.forEach(System.out::println); } }
Output1 2 3 4 5
package com.logicbig.example.arrays;
import java.util.Arrays; import java.util.stream.LongStream;
public class StreamExample2 {
public static void main(String... args) { long[] arr = {1L, 2, 3, 4, 5}; LongStream stream = Arrays.stream(arr); stream.forEach(System.out::println); } }
Output1 2 3 4 5
package com.logicbig.example.arrays;
import java.util.Arrays; import java.util.stream.DoubleStream;
public class StreamExample3 {
public static void main(String... args) { double[] arr = {1.2, 2.2, 3.1, 4.4, 5.3}; DoubleStream stream = Arrays.stream(arr); stream.forEach(System.out::println); } }
Output1.2 2.2 3.1 4.4 5.3
package com.logicbig.example.arrays;
import java.util.Arrays; import java.util.stream.Stream;
public class StreamExample4 {
public static void main(String... args) { String[] arr = {"Apple", "banana", "pie"}; Stream<String> stream = Arrays.stream(arr); stream.forEach(System.out::println); } }
OutputApple banana pie
package com.logicbig.example.arrays;
import java.util.Arrays; import java.util.stream.IntStream;
public class StreamExample5 {
public static void main(String... args) { int[] arr = {1, 2, 3, 4, 5}; //index based IntStream stream = Arrays.stream(arr, 2, 5); stream.forEach(System.out::println); } }
Output3 4 5
|
|