how to selectively filter items in a collection
- by Samuel
I use the following snippet to filter the list of selected users, where isSelected is a boolean variable. Is there a simpler way (helper function) to populate the selectedUsers collection instead of writing the following lines of code.
List<User> selectedUsers = new ArrayList<User>(0);
for (User user : this.getUsers()) {
if (user.isSelected()) {
selectedUsers.add(user.getId());
}
}