forEach(BiConsumer): This method is available in java.util.Hashtable class of Java.
Syntax:
void java.util.Hashtable.forEach(BiConsumer<? super K, ? super V> 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.Hashtable;public class HashtableforEach {public static void main(String[] args) {Hashtable<String, Integer> hashtable =new Hashtable<String, Integer>();hashtable.put("Hello", 1);hashtable.put("World", 2);hashtable.forEach((k, v) ->System.out.println(k + "==" + v));}}
Output:
Hello==1
World==2
No comments:
Post a Comment