Skip to content

Tag: java-stream

Java 8 Remove 1 List from Other

I have two list of different Objects. I want to remove the list of School objects from List of World objects based on schoolName and location. I cannot use equals and hashCode methods on those two fields as it is creating some other problem. Please help me how it can be done using streams. Answer You can use …

Combine two Stream into one Flux

How can I combine two streams Stream<String> into Flux? What I understand is that I might need to use Flux create method to create this but I am not really sure about it: Please help. Answer Concat the Streams into one and then invoke Flux#fromStream: Another way of doing this would be to create a Flux …

parallelStream() java 1.8 vs 11

Consider the following code: When it is compiled and run with java 11, it returns the following: But with java 1.8, it returns different result: Why results are different? Answer Both results are consistent with the Java Memory Model. One possible ordering in which execution occurs is: but, because you don&#8…

Direct conversion from Collection to LongStream

I have a Collection<Long> (obtained from a Map<UUID, Long>’s values() method) and I would like to convert it into a LongStream. The simplest way I can think of is: However it strikes me that there should be a simpler way to obtain primitive streams from Collections of boxed equivalents. I ch…