Is there a simple way of removing null references from a HashSet like
the way we can delete them from a List using list.removeAll(Collections.singletonList(null)) ?
Is there a simple way of removing null references from a HashSet like the
Share
Since a
Setcan not contain the same value twice (includingnull, if it is supported by the specificSetimplementation), simply doingset.remove(null)would be sufficient.Note that you don’t even need to check for the existence of
nullbefore, becauseremove(null)will simply do nothing if theSetdoesn’t containnull.