I want to take input and apply a parallel stream to it, then I want it to be output as a list. The input can be any List or any collection on which we can apply streams.
My problems here are that if we want the output to appear as a map, we have an option from java like
list.parallelStream().collect(Collectors.toConcurrentMap(args))
But there is no option that I can see for collecting from a parallel stream in a streaming safe way of providing a list as output. I see another use case
list.parallelStream().collect(Collectors.toCollection(<Concurrent Implementation>))
in this way we can provide various parallel implementations in the collection method. But I think that only the CopyOnWriteArrayList List implementation is present in java.util.concurrent. We could use a different implementation of the queue here, but they will not look like a list. I mean, we can get a list in a workaround.
Could you tell me what is the best way if I want the result to be like a list?
Note. I could not find any other posts related to this, any link would be helpful.
source share