At one point in my code, I created a Set from a map. Now I want to recreate the same map form, so I want to convert the HashS
These are some toMap utility in common libraries, but unfortunately none of them support Set directly so you need to do Set#toArray() first. (I left out Guava for Neil's answer which is arguably the best)
Map
Map map = MapUtils.putAll(new HashMap(), entrySet.toArray());
// convert to array and recover the type...
@SuppressWarnings("unchecked")
Map map = Map.ofEntries(entrySet.toArray(new Map.Entry[0]));
// You need to copy again if you want a mutable one
Map hashmap = new HashMap<>(map);