replaceAll(BiFunction): This method is available in java.util.HashMap class of Java.
Syntax:
void java.util.HashMap.replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
This method takes one argument. This method replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
Parameters: One parameter is required for this method.
function: the function to apply to each entry.
Returns: NA
Exceptions: NA
Approach
Java
import java.util.HashMap;import java.util.function.BiFunction;public class HashMapreplaceAll {public static void main(String[] args) {HashMap<String, Integer> hashMap =new HashMap<String, Integer>();hashMap.put("1", 1);hashMap.put("2", 2);BiFunction<? super String, ?super Integer, ? extends Integer> function =(a, b) -> Integer.parseInt(a) + 12;hashMap.replaceAll(function);System.out.println(hashMap);}}
Output:
{1=13, 2=14}
No comments:
Post a Comment