Building a Map of Set using Java Streams
Have you looked at .groupingBy() and .toSet()?

Map&lt;Integer, Set&lt;MyObject&gt;&gt; collected = Stream.of(...)
    .collect(Collectors.groupingBy(Map.Entry::getKey,
                                   Collectors.mapping(Map.Entry::getValue, Collectors.toSet())));


You possibly want .groupingByConcurrent() instead, though it is not exactly clear why.

Not a repl.it, but a JShell log:

U:\&gt;jshell
|  Welcome to JShell -- Version 13
|  For an introduction type: /help intro

jshell&gt; class MyObject { }
|  created class MyObject

jshell&gt; Map&lt;Integer, Set&lt;MyObject&gt;&gt; result = Stream.of(
   ...&gt;    Map.entry(123, new MyObject()),
   ...&gt;    Map.entry(123, new MyObject()),
   ...&gt;    Map.entry(234, new MyObject())
   ...&gt; ).collect(
   ...&gt;    Collectors.groupingByConcurrent(
   ...&gt;       Map.Entry::getKey,
   ...&gt;       Collectors.mapping(
   ...&gt;          Map.Entry::getValue,
   ...&gt;          Collectors.toSet()
   ...&gt;       )
   ...&gt;    )
   ...&gt; );
result ==&gt; {234=[MyObject@78c03f1f], 123=[MyObject@5ce81285, MyObject@52a86356]}

jshell&gt;