Pardon my newbie-ness to Java as I am not experienced enough to know the most efficient way to do this. I have a hashmap like below, but it would have like 40,000 entries:
Map <String, String> someHashmap = new HashMap <String, String> ();
someHashmap.put("filepath1", null);
someHashmap.put("filepath2", "tag1");
someHashmap.put("filepath3", "tag2");
I want to determine how many value match null so that I can determine if any are null. Of course I could do a regular loop to check but am wondering if there is a more efficient way, thanks
You can use the
containsValuemethod, which states:However keep in mind, that if you have a large dataset(and it seems you do), you should create a separate data structure to keep track of the values that allow for O(1) lookup time, rather than O(n) time, as suggested in other answers.