What would be the best way of optimizing the below code further
public List<GroupDTOv2> getAllGroups(String xTenantId, CourseType courseType, String courseId, ContextType contextType, String contextId) throws AuthenticationException {
final List<GroupV2> groups = groupV2Repository.findByTenantIdAndCourseTypeAndCourseIdAndContextTypeAndContextId(xTenantId, courseType, courseId, contextType, contextId);
final RosterDTOv2 roster = rosterServiceFacade.getRoster(xTenantId, courseType, courseId, contextType, contextId);
final ArrayList<GroupDTOv2> groupDtoList=new ArrayList<>();
groups.stream().forEach(group -> {
final GroupDTOv2 groupDTO=new GroupDTOv2();
BeanUtils.copyProperties(group,groupDTO);
roster.getUsers().forEach(userDTOv2 -> {
if(userDTOv2.getUserId().equalsIgnoreCase(group.getTeamLeadId())){
groupDTO.setTeamLead(userDTOv2);
}
if(group.getTeamMemberIds().contains(userDTOv2.getUserId())){
groupDTO.getTeamMembers().add(userDTOv2);
}
});
groupDtoList.add(groupDTO);
});
return groupDtoList;
}
If we use stream twice to set the team-lead object and the team members i think the cost would be high,In that case what would be the mostappropriate way