The
forEach(BiConsumer) method of
Properties class perform the BiConsumer operation on each entry of hashtable until all entries have been processed or the action throws an exception. The BiConsumer operation is a function operation of key-value pair of hashtable performed in the order of iteration. Method traverses each element of Hashtable until all elements have been processed by the method or an exception occurs. Exceptions thrown by the Operation are passed to the caller.
Syntax:
public void forEach(BiConsumer action)
Parameters: This method accepts a parameter
action of BiConsumer type that represents what action are to be performed on the properties elements.
Returns: This method do not return anything.
Exceptions: This method throws
NullPointerException if the action is null.
Below programs illustrate the forEach(BiConsumer) method:
Program 1:
Output:
Properties 1: {Book=500, Mobile=5000, Pen=10, Clothes=400}
Key : Clothes, Value : 500
Key : Mobile, Value : 5100
Key : Pen, Value : 110
Key : Book, Value : 600
Program 2: To show NullPointerException