![]() |
VOOZH | about |
The forEach(BiConsumer) method of Hashtable 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<? super K, ? super V> action)
Parameters: This method takes a parameter name BiConsumer which represents the action to be performed for each element.
Returns: This method returns nothing.
Exception: This method throws:
Below programs illustrate the forEach(BiConsumer) method:
Program 1:
Key : Booklet, Value : 2600 Key : Clothes, Value : 500 Key : Mobile, Value : 5100 Key : Pen, Value : 110 Key : Book, Value : 600
Program 2: To Show NullPointerException
Exception: java.lang.NullPointerException
References: https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html#forEach-java.util.function.BiConsumer-