0

How to convert Stream to List

Using Collectors.toList():

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ConvertStreamToList {

    public static void main(String[] args) {
        Integer[] numbers = { 1, 2, 3, 4 };
        Stream<Integer> arrayStreams2 = Arrays.stream(numbers);

        System.out.println(arrayStreams2.collect(Collectors.toList()));
    }
}

Output:

[1, 2, 3, 4]
add comment
Suggest a different solution or add another example