In this post, we will learn to convert Iterable to Stream in Java.
To convert Iterable to Stream, we need to follow the steps below:
- Convert Iterable to Spliterator and
- Call the static method stream() from StreamSupport class.
Assume that we have an iterator object like:
Iterable<String> iterable = Arrays.asList("Radha", "Krishnan", "Coder", "Sathi");
Now, convert this
iterable object to stream:
Stream<String> stream = StreamSupport.stream(iterable.spliterator(), false);
In this way, we can easily convert iterable to stream in Java.
Leave a Reply