input: Map<String, Set> map
eg: map =
{"a"=[],
"b"=["b", "1", "2", "4"]}
expected output : 5 ("b" appears as key and value. should be counted as one)
this is what i have tried so far. is there a better way to do this?
Set<String> o = new HashSet<String>();
o.addAll(m1.keySet());
o.addAll(m1.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()));
System.out.println(o.size());
Is it possible to stream on the map's entryset to arrive at this output? Also creating a separate hashset looks unnecessary just to get a count