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