Hi! I was very happy to find such a library until I discovered that there are no examples or HOWTO's. I have no idea how to stream my ArrayList. list.stream() is not found. Is there any interface for wrapping lists in order to stream? Thanks in advance!
Last edit: Anonymous 2015-02-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've found out that I can achieve this by using StreamSupport.of(list). Not very clear from the first time. But nevertheless, some examples are needed! Thanks one more time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is mentioned in the "general" section in the release notes:
- Use one of the j8.u.s.StreamSupport#stream(Collection, ...) methods or the
j8.u.s.StreamSupport#parallelStream(Collection) method to create a Stream from
a java.util.Collection
Fortunately, this is more or less the only thing you need to know to use the library.
Otherwise the API is identical to the official Java 8 API, with the exception of static and default interface methods which are always located in a corresponding "companion" class with same name as the interface but with an "s" appended ("Comparator" -> "Comparators").
The only exception to this exception is the Stream interface, whose static and default methods are all located in StreamSupport. Hope that answers your question.
Last edit: Stefan Zobel 2015-02-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yeah, your answer helped me a lot. I am sorry that I didn't notice that in releases section before, because I used Maven central repository instead. Thank for the quick response! Have a nice day!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hi! I was very happy to find such a library until I discovered that there are no examples or HOWTO's. I have no idea how to stream my ArrayList. list.stream() is not found. Is there any interface for wrapping lists in order to stream? Thanks in advance!
Last edit: Anonymous 2015-02-05
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
I've found out that I can achieve this by using
StreamSupport.of(list)
. Not very clear from the first time. But nevertheless, some examples are needed! Thanks one more time.StreamSupport.of(list) would return a Stream<List>, i.e. your ArrayList would be the single element in the stream. That's not what you want. Use
1) public static <T> Stream<T> stream(Collection<? extends T> c)
or
2) public static <T> Stream<T> parallelStream(Collection<? extends T> c)
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
It is easiest to use the static methods
1) public static <T> Stream<T> stream(Collection<? extends T> c)
2) public static <T> Stream<T> parallelStream(Collection<? extends T> c)
in the j8.u.s.StreamSupport class.
In addition there are
3) public static <T> Stream<T> stream(Collection<? extends T> c, int characteristics)
4) public static <T> Stream<T> stream(Collection<? extends T> c, int characteristics, boolean parallel)
in the same class. I would prefer 1) or 2), depending on whether you want a sequential or a parallel stream. Hope that helps.
It is mentioned in the "general" section in the release notes:
Fortunately, this is more or less the only thing you need to know to use the library.
Otherwise the API is identical to the official Java 8 API, with the exception of static and default interface methods which are always located in a corresponding "companion" class with same name as the interface but with an "s" appended ("Comparator" -> "Comparators").
The only exception to this exception is the Stream interface, whose static and default methods are all located in StreamSupport. Hope that answers your question.
Last edit: Stefan Zobel 2015-02-05
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Yeah, your answer helped me a lot. I am sorry that I didn't notice that in releases section before, because I used Maven central repository instead. Thank for the quick response! Have a nice day!
No worries. Please ask when you have further questions.