merge(Object, Object, BiFunction): This method is available in java.util.Properties class of Java.
Syntax:
Object java.util.Properties.merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction)
This method takes three arguments. If the specified key is not already associated with a value or is associated with null, associate it with the given non-null value.
Parameters: Three parameters are required for this method.
key: key with which the resulting value is to be associated.
value: the non-null value to be merged with the existing value associated with the key or if no existing value or a null value is associated with the key, to be associated with the key.
remappingFunction: the remapping function to recompute a value if present.
Returns: the new value associated with the specified key, or null if no value is associated with the key.
Exceptions: NA
Approach
Java
import java.util.Properties;import java.util.function.BiFunction;public class Propertiesmerge {public static void main(String[] args) {Properties properties = new Properties();properties.put("Hello", "World");properties.put("C++", "Program");properties.put("Java", "Program");Object key = "Hello", value = "World";BiFunction<? super Object, ? super Object,?> remappingFunction = (a, b) -> a;System.out.println(properties.merge(key,value, remappingFunction));}}
Output:
World
No comments:
Post a Comment