Last Updated : 11 Jul, 2025
The List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes. A Stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. Below are various methods to convert List to Stream in Java:
List.stream()Algorithm:
// Java Program to convert
// List to Stream in Java 8
import java.util.*;
import java.util.stream.*;
import java.util.function.Function;
class GFG {
// Generic function to convert a list to stream
private static <T> Stream<T> convertListToStream(List<T> list)
{
return list.stream();
}
public static void main(String args[])
{
// Create a stream of integers
List<String> list = Arrays.asList("GeeksForGeeks",
"A computer portal",
"for Geeks");
// Print the List
System.out.println("List: " + list);
// Convert List to stream
Stream<String> stream = convertListToStream(list);
// Print the Stream
System.out.println("Stream from List: "
+ Arrays.toString(stream.toArray()));
}
}
List: [GeeksForGeeks, A computer portal, for Geeks] Stream from List: [GeeksForGeeks, A computer portal, for Geeks]
// Java Program to convert
// List to Stream in Java 8
import java.util.*;
import java.util.stream.*;
import java.util.function.*;
class GFG {
public static void main(String args[])
{
// Create a stream of integers
List<String> list = Arrays.asList("GeeksForGeeks",
"A computer portal",
"for",
"Geeks");
// Print the List
System.out.println("List: " + list);
// Create the predicate for item starting with G
Predicate<String> predicate = new Predicate<String>() {
@Override
public boolean test(String s)
{
// filter items that start with "G"
return s.startsWith("G");
}
};
System.out.println("Stream from List with items"+
" starting with G: ");
// Convert List to stream
list.stream()
.filter(predicate)
.forEach(System.out::println);
}
}
List: [GeeksForGeeks, A computer portal, for, Geeks] Stream from List with items starting with G: GeeksForGeeks Geeks
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