Java HashMap merge() The Java HashMap merge() method inserts the specified key/value mapping to the hashmap if the specified key is already not present . If the specified key is already associated with a value, the method replaces the old value with the result of the specified function.