Question 8
The merge(K key, V value, remappingFunction) function is defined as: If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null.
Consider the Java code given below.
import java.util.*;
public class DepartmentScores { public static void main(String[] args) { Map<String, Integer> dept1 = new TreeMap<>(); dept1.put("HR", 75); dept1.put("Finance", 80); dept1.put("Tech", 95);
Map<String, Integer> dept2 = new TreeMap<>(); dept2.put("Finance", 85); dept2.put("Tech", 90); dept2.put("HR", 78); dept2.put("Admin", 70);
Map<String, Integer> combined = new TreeMap<>();
for (Map.Entry<String, Integer> e : dept1.entrySet()) combined.put(e.getKey(), e.getValue()); //LINE 1
for (Map.Entry<String, Integer> e : dept2.entrySet()) combined.merge(e.getKey(), e.getValue(), (oldVal, newVal) -> Math.max(oldVal, newVal));
System.out.println(combined); }}Choose the correct option.