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