replaceAll(BiFunction): This method is available in java.util.IdentityHashMap class of Java.
Syntax:
void java.util.IdentityHashMap.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.IdentityHashMap;import java.util.function.BiFunction;public class IdentityHashMapreplaceAll {public static void main(String args[]) {IdentityHashMap<String, Integer> identityHashMap =new IdentityHashMap<String, Integer>();identityHashMap.put("1", 1);identityHashMap.put("2", 2);BiFunction<? super String, ? super Integer,? extends Integer> function = (a, b) ->(Integer.parseInt(a) + b);identityHashMap.replaceAll(function);System.out.println(identityHashMap);}}
Output:
{1=2, 2=4}
No comments:
Post a Comment