You can use groupingBy instead of toMap:

Map<String, Set<A>> sysUidToAMap =  
    mySet.stream()
         .collect(Collectors.groupingBy(A::getSystemID,
                                        Collectors.toSet()));
Answer from Eran on Stack Overflow
🌐
DZone
dzone.com › coding › java › converting collections to maps with jdk 8
Converting Collections to Maps With JDK 8
January 15, 2018 - With this class in place, the demonstration class CollectionToMapDemo shows how easy it is with JDK 8 to convert various Java collection types (Set, List, and even arrays) to a Map.
🌐
CodingTechRoom
codingtechroom.com › question › convert-set-to-map-java-8
How to Convert a Set to a Map with a Set as the Value in Java 8? - CodingTechRoom
Set<String> set = new ... can easily convert a Set to a Map where the values are Sets by employing the Stream API along with the Collectors utility....
🌐
Techie Delight
techiedelight.com › home › java › convert set to map in java
Convert Set to Map in Java | Techie Delight
July 7, 2026 - Set : [WHITE=#FFFFFF, GRAY=#808080, BLACK=#000000] Map : {WHITE=#FFFFFF, GRAY=#808080, BLACK=#000000} We can also use method references instead of lambda expressions. Collectors class provides several overloaded versions of toMap() method:
🌐
Java Development Journal
javadevjournal.com › home › how to convert a map to set in java
How to Convert a Map to Set in Java | Java Development Journal
November 4, 2020 - Learn how to Convert a Map to Set in Java. Explore how to convert a map to set in Java using plain JDK and Java 8 Stream API.
🌐
Java67
java67.com › 2019 › 05 › how-to-convert-stream-to-list-set-map-in-java.html
How to Convert a Stream to List, Set, and Map in Java? Example Tutorial | Java67
Btw, if you are interested in learning other Java 8 features apart from lambdas and stream like Date and Time API, Optionals, etc then you can also check out this nice little course What's New in Java 8 from Pluralsight. Our complete Java program demonstrates how you can use the Collectors class to convert a Stream of values into List, Set, Map, and ConcurrentMap in Java.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Map.html
Map (Java Platform SE 8 )
July 21, 2026 - The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.
🌐
Blogger
javarevisited.blogspot.com › 2016 › 04 › 10-examples-of-converting-list-to-map.html
10 Examples of Converting a List to Map in Java 8
Prior to Java 8, you can do this by iterating through the List and populating the map by keys and values. Since it's an iterative approach and if you are looking for a functional solution then you need to use the stream and lambda expression, along with some utility classes like Collectors, which provides several useful methods to convert Stream to List, Set...
🌐
Mkyong
mkyong.com › home › java8 › java 8 – convert list to map
Java 8 – Convert List to Map | mkyong.com
May 26, 2017 - Few Java 8 examples to show you how to convert a List of objects into a Map, and how to handle the duplicated keys. Hosting.java · package com.mkyong.java8 public class Hosting { private int Id; private String name; private long websites; public Hosting(int id, String name, long websites) { Id = id; this.name = name; this.websites = websites; } //getters, setters and toString() } Create a list of the Hosting objects, and uses Collectors.toMap to convert it into a Map.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › how to convert list to map in java
How to Convert List to Map in Java | Baeldung
April 4, 2025 - Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.
🌐
Java Guides
javaguides.net › 2018 › 12 › java-convert-map-to-set-example.html
Java: Convert Map to Set
May 30, 2024 - This guide will cover how to convert a map to a set, including converting keys to a set, values to a set, and entries to a set. ... In Java, a Map is a collection that maps keys to values, with each key mapping to at most one value. A Set is a collection that contains no duplicate elements.
🌐
CMU
web2.qatar.cmu.edu › cs › 15121 › notes › sets-and-maps
Sets and Maps
For example, imagine I’m building a music manager and want to use a map to link the playlist name with the songs in the list. The key is the playlist name, but it can only map to one thing. So how do I associate it with more than one song? Easy, I put those songs in a list (or a set), and associate the list with the key. https://docs.oracle.com/javase/8/docs/api/java/util/Map.html
🌐
Baeldung
baeldung.com › home › java › java collections › java map › convert a map to an array, list or set in java
Convert a Map to an Array, List or Set in Java | Baeldung
June 9, 2025 - A solid grasp of the fundamentals will go a long way to help minimize these issues. Get started with understanding multi-threaded applications with our Java Concurrency guide: ... Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.