HashMap Java get value if it exists

Sure

Integer houme = hashMapHouse.get("houme1");

if (null == houme ) {
    // not exists 
} else {
    // exists 
} 

In Java 8 you can use the getOrDefault method:

int var = hashMapHouse.getOrDefault("home1", 0);

It's the cleanest solution, in a single line you can get either the value for the key if it exists, or a predefined default value to indicate that it doesn't exist - 0 in this case.


From the docs:

A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

If you are not using null as value then you can use the get() method once and do it like this:

Integer var = hashMap.get(key);
if (var != null) {
    // value exists
}