Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class User {
- private final int id;
- private final String firstName;
- private final String lastName;
- private final Boolean active;
- // Для краткости я пропустил конструкторы, геттеры и сеттеры
- }
- public static List<String> activeById(List<User> us) {
- List<User> users = new ArrayList<User>();
- for (User u: us) {
- if (u.getActive()) users.add(u);
- }
- Collections.sort(users, new Comparator<User>() {
- public int compare(User a, User b) {
- return a.getId() - b.getId();
- }
- });
- List<String> finalUsers = new ArrayList<String>();
- for (User u: users) {
- finalUsers.add(u.getLastname());
- }
- return finalUsers;
- }
- List<User> inputUsers = new ArrayList<User>();
- inputUsers.add(new User(11, "Nick", "Smith", false));
- inputUsers.add(new User(89, "Ken", "Pratt", true));
- inputUsers.add(new User(23, "Jack", "Sparrow", true));
- List<User> activeUsersById = activeById(inputUsers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement