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