Java HashMap replace(key, oldValue, newValue) Method
The replace(key, oldValue, newValue) method of the HashMap class in Java is used to conditionally replace the value of a specified key if, and only if, the current value matches the specified old value. Example 1: This example demonstrates replacing a value only if the key is mapped to the given old