#340 Grouping Users by Registration Date
Group the List<User> data by user registration date (registrationDate):
- Users registered at the same time must be placed in a
List<User> - The final result must be the data structure
Map<LocalDateTime, List<User>>
public class Main {
public static void main(String[] args) throws InterruptedException {
var users = List.of(
User.of("jerry-Smith_43", "Jerry", "Smith", LocalDateTime.of(2020, 7, 23, 17, 30), List.of(Role.of("USER", List.of("READ", "CREATE", "UPDATE")))),
User.of("rick-sunches-the-best-15", "Rick", "Sunches", LocalDateTime.of(2020, 7, 23, 17, 30), List.of(Role.of("ADMIN", List.of("READ", "CREATE", "UPDATE", "DELETE")))),
User.of("mortyEvil", "Morty", "Smith Evil", LocalDateTime.of(2021, 8, 17, 20, 30), List.of(Role.of("ADMIN", List.of("READ", "CREATE", "UPDATE", "DELETE")))));
...
}
}
@AllArgsConstructor(staticName = "of")
@Data
public class User {
private String username;
private String firstName;
private String lastName;
private LocalDateTime registrationDate;
private List<Role> roles;
}
@AllArgsConstructor(staticName = "of")
@Data
public class Role {
private String roleName;
private List<String> privileges;
}
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