There is a difference between null , which means nothing at all, and an empty HashSet . An empty HashSet is an actual HashSet , but one that accidentally matches the absence of any elements in it. This is similar to how null does not match the empty string "" , which is a string that has no characters.
To check if a HashSet empty, use the isEmpty method:
if(test.get("1").isEmpty()){ System.out.println("Hello world"); }
Hope this helps!
source share