I have a HashMap groups
which maps to ArrayList
objects for its values. I wanted to re-assign the values given they meet a particular condition (i.e. in this case, they are present in another list) and came across the forEach
method. Here's how I implemented it. I could not find any documentation as to whether it is able to transform my data hence my question.
Here's the code:
groups.get(request.getGroup()).forEach(
member -> {
int updatedMemberIndex = request.getGroupMembers().indexOf(member);
if (updatedMemberIndex != -1)
member = request.getGroupMembers().get(updatedMemberIndex);
}
);
And here are the method signatures for the relevant methods in request
object:
List<GroupMember> getGroupMembers()
Group getGroup()