Properties replaceAll(BiFunction) in Java

replaceAll(BiFunction): This method is available in java.util.Properties class of Java.

Syntax:

void java.util.Properties.replaceAll(BiFunction<? super Object, ? super Object, ?> function)

This method takes one argument. This method replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.

Parameters: One parameter is required for this method.

function: the function to apply to each entry.

Exceptions: NA

Approach

Java

import java.util.Properties;
import java.util.function.BiFunction;

public class PropertiesreplaceAll {
    public static void main(String[] args) {

        Properties properties = new Properties();

        properties.put("Hello", "World");
        properties.put("C++", "Program");
        properties.put("Java", "Program");

        BiFunction<? super Object, ? super Object,
?> function = (a, b) -> a;
        properties.replaceAll(function);
        System.out.println(properties);
    }
}

Output:

{Java=Java, C++=C++, Hello=Hello}


No comments:

Post a Comment