I have a hashmap that is 101 keys in size, but I know for sure about 6 of those have no data inside, and there may be more without data as well. What exactly is inside the empty indexes? Is it null? or is there a Hash(index).isEmpty() method that I can use to see if its empty?
I realize there is a isEmpty method inside hashmap, but I thought that only checked if the entire map was empty not just a single index.
Well, for the keys to arrive there with no data, you have to
putthem there.If you did
map.put(key, null)then yes the data for that key isnull. You always have to give the second parameter to the method, you can’t justmap.put(key).If you know for sure that a certain key should have no data you could try going into debug mode and putting a watch for
myMap.get(myEmptyKey)and see what you get (in case that no data is an empty object or something else, you should be able to see that).Edit: Some code would be useful to help you, but if I understand correctly you do something like this:
Well, if you do that and try to do
map.get("X"), but you never actually put anything for that key (becaus no object matched criteria X), you will most definitely get back anull.On the other hand, if you did something like
then you could check if a category is empty by doing
map.get("x").isEmpty()since List has that method (and it would be empty if no object matched the key criteria).