Skip to content
Advertisement

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 filter:

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 using Flux#fromStream and then

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’t do anything to ensure that the set and print

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 checked StreamSupport and could only find StreamSupport.longStream(Spliterator.OfLong spliterator, boolean parallel),

Convert a list of integers into a comma-separated string

I was trying to convert a list of Integers into a string of comma-separated integers. Collectors.joining(CharSequence delimiter) – Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order. I am getting an error in line number 8: The method collect(Collector<? super Integer,A,R>) in the type Stream is not applicable for the arguments (Collector<CharSequence,capture#20-of ?,String>)

Advertisement