A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/arrays-stream-method-in-java/ below:

Arrays.stream() Method in Java - GeeksforGeeks

Arrays.stream() Method in Java

Last Updated : 11 Jul, 2025

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:

Java
// Java program to demonstrate Arrays.stream() method
import java.util.*;
import java.util.stream.*;

class GFG {
    public static void main(String[] args) {

        // create a String array
        String[] arr = { "Geeks", "for", "Geeks" };

        // use Arrays.stream() to convert array into Stream
        Stream<String> st = Arrays.stream(arr);

        st.forEach(s -> System.out.print(s + " "));
    }
}
Syntax of Arrays.stream() Method 1. To Convert Entire Array

public static <T> Stream<T> stream(T[] array)

Parameters:

Return Type: This method returns a Stream<T>, which is a sequential stream of the elements of the provided array.

2. To Convert a Range within an Array

public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive)

Parameters:

Return Type: This returns a Stream<T>, which is a sequential stream that contains elements from the specified range in the array.

Example 1: Convert an int Array to an IntStream

In this example, we create an IntStream from a full int array and print each element in sequence.

Java
// Java program to Convert an 
// int Array to an IntStream
import java.util.*;
import java.util.stream.*;

class GFG {

    public static void main(String[] args) {
        
        // create an integer array
        int arr[] = { 1, 2, 3, 4,};

        // use Arrays.stream() to convert
        // array into Stream
        IntStream st = Arrays.stream(arr);

        st.forEach(s -> System.out.print(s + " "));
    }
}
Example 2: Convert a Specific Range of a String Array to a Stream

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.

Java
// Java program to Convert a Specific Range
// of a String Array to a Stream
import java.util.*;
import java.util.stream.*;

class GFG {
    public static void main(String[] args) {

        // create a String array
        String[] arr = { "Geeks", "for", "Geeks", };

        // use Arrays.stream() to convert
        // array into Stream
        Stream<String> st = Arrays.stream(arr, 1, 2);

        st.forEach(s -> System.out.print(s + " "));
    }
}
Example 3: Convert a Specific Range of an int Array to an IntStream

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.

Java
// Java program to Convert a Specific Range
// of an int Array to an IntStream
import java.util.*;
import java.util.stream.*;

class GFG {

    public static void main(String[] args) {
        
        // create an integer array
        int arr[] = { 1, 2, 3, 4,};

        // use Arrays.stream() to convert
        // array into Stream
        IntStream st = Arrays.stream(arr, 1, 3);

        // Displaying elements in Stream
        st.forEach(s -> System.out.print(s + " "));
    }
}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4