Simple question about HashMaps

Discussion in 'Plugin Development' started by LRFLEW, Jan 17, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    LRFLEW

    I have a HashMap I'm using to set players to a setting. The thing is, to check to make sure no errors occur, I'm using containsKey(key) to test to make sure a setting exists before calling it. I'm worried about null objects, though. If a key has a null value, will containsKey(key) return true or false?
     
  2. Offline

    Reil

    I think the best solution would be to check for null values before using containsKey.
     
  3. Offline

    LRFLEW

    Yes, but I wasn't asking for the best solution, I was asking for a yes or no answer to if containsKey returns true if value is null.
     
  4. Offline

    Vollch

    Code:
    Logger.getLogger("Minecraft").info(Boolean.toString(new HashMap<Object, Object>().containsValue(null)));
    2011-01-18 06:30:51 [INFO] false
     
  5. Offline

    Reil

    I'd imagine that it would only return true if you added a value to the hashmap using null as a key, and I'm not sure that's even possible.
     
  6. Offline

    LRFLEW

Thread Status:
Not open for further replies.

Share This Page