From a Stream, a Map. of Lists — We found that collecting a stream to a map is not completely safe, here in this article: Java Streams: Collect a Stream to Map
From a Stream, a Map.danio-quero.medium.com I also said that two possible solutions came to my mind, here is the first one. When collecting to a map, if the keyMapper finds a non-unique key an exception is thrown, saying…