how to selectively filter items in a collection
Posted
by Samuel
on Stack Overflow
See other posts from Stack Overflow
or by Samuel
Published on 2010-05-17T05:06:57Z
Indexed on
2010/05/17
5:10 UTC
Read the original article
Hit count: 209
java
|collections
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());
}
}
© Stack Overflow or respective owner