Skip to content

Tag: collectors

Custom Collector that cannot work in parallel

I have made a custom collector that uses a MessageDigest to create a hash. In general MessageDigest does not work in parallel. The issue I’m seeing is in the combiner() method. It is not possible to combine two MessageDigest objects. When I return null it seems to work but if I throw an UnsupportedOpera…

Java 8 List from String and List of String

I want to generate a list of strings, comprising id and external ids, from a list of Bean. I got it using the below code, but here I need to do the stream twice. Is there any better way to rewrite this code? Answer Use Stream.concat inside the flatMap operation:

Java Collectors Grouping By

I have an input of integers and I would like to sort all even numbers before all odd ones in ascending order and preserve the odds order. I am pretty sure I can achieve that with collectors and/or downstream collectors, but I am not sure how to do it. I would like to know how can I sort the false