Map<Long, Employee.status> prevStatus = empRecords.stream()
.collect(Collectors.toMap(employeeRecord::getEmloyeeID,
employeeRecord::getEmployeeStatus));
I already have the above code, I need to add a similar operation but instead of creating a new Map I want to add the result to the existing map.
prevStatus = empRecords.stream()
.collect(Collectors.**toMap**(employeeRecord::getEmloyeeID,
employeeRecord::**getUSEmployeeStatus**));
You can create a new Map and add its entries to the existing Map:
prevStatus.putAll(
empRecords.stream()
.collect(Collectors.toMap(employeeRecord::getEmloyeeID,
employeeRecord::getUSEmployeeStatus)));
Or you can use forEach instead of collect:
empRecords.stream()
.forEach(emp -> prevStatus.put(emp.getEmloyeeID (),
emp.getEmployeeStatus()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With