#337 Grouping Profiles by Organization and Group
Group the data so that the first Map uses organizationId as the key and contains another Map as its value, where groupId is the key and List<Profile> is the value:
static public class Profile {
public Long id;
public Long organizationId;
public Long groupId;
}
public Map<Long, Map<Long, List<Profile>>> groupByOrgIdAndGroupId(List<Profile> data) {
...
}
Example:
[1, 0, 1]
[2, 0, 1]
[3, 0, 2]
[4, 1, 1]
[5, 1, 2]
Result:
{
"0": {
"1" : [{1..}, {2..}],
"2" : [{3..}],
}
"1": {
"1" : [{4..}],
"2" : [{5..}]
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor