![]() |
VOOZH | about |
Arrays.stream() method is used to get a sequential Stream from the elements of an array passed as a parameter. Below is a simple example that uses Arrays.stream() to convert a String array into a Stream for sequential processing.
Example:
Geeks for Geeks
public static <T> Stream<T> stream(T[] array)
Parameters:
T[] (an array of any object type).Return Type: This method returns a Stream<T>, which is a sequential stream of the elements of the provided array.
public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive)
Parameters:
array: The array to be partially converted to a stream.startInclusive: The starting index of the range to include in the stream (inclusive).endExclusive: The end index of the range (exclusive).Return Type: This returns a Stream<T>, which is a sequential stream that contains elements from the specified range in the array.
In this example, we create an IntStream from a full int array and print each element in sequence.
1 2 3 4
In this example, we will generate a Stream from a specific range within a String array and then will print the elements within the selected range.
for
In this example, we will create an IntStream from a range of elements in an int array and then we will print only those elements within the specified range.
2 3