A very common operation on maps of collections is to create a new collection with an initial value when the key is not present, or if the key is present, do some function on the
Here's another alternative:
Set set = m.computeIfAbsent (key , k -> new HashSet<> ()); set.add(set.size() + 1);
The only reason this is a two liner (instead of one) is the need to obtain the current size of the Set in order to decide which value to add to it.
Set