I have list of object which in turn has list object in it.
List<User> users = ....;
List<Roles> roles=....;
I want to iterate over user and roles in it and need to compare user.department with role.department list.
User class contains a list of Roles, and a Role contains a list of Departments and And User also contains a Department as String type.
My business logic is different it's something like this. For ease of understanding, I have taken this as an example.
Optional<Role> matchedRole= users
.stream()
.flatMap(u -> u.getRoles().stream())
.filter(r -> r.getDepartmenList().contains(u.getDepartment())
.findFirst();
Now, how can I access u and the inner stream? Thanks in advance.
Userclass contains a list ofRoles, and aRolecontains a list ofDepartments? AndUseralso contains aDepartment?