Properties forEach(BiConsumer) in Java

forEach(BiConsumer): This method is available in java.util.Properties class of Java.

Syntax:

void java.util.Properties.forEach(BiConsumer<? super Object, ? super Object> action)

This method takes one argument. This method performs the given action for each entry in this map until all entries have been processed or the action throws an exception.

Parameters: One parameter is required for this method.

action: The action to be performed for each entry.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Properties;

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

        Properties properties = new Properties();

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

        properties.forEach((key, value) ->
System.out.print(key + " == " + value + " "));

    }
}

Output:

Java == Program C++ == Program Hello == World 


No comments:

Post a Comment