Filtering a list of JavaBeans with Google Guava

前端 未结 9 746
夕颜
夕颜 2020-12-01 06:59

In a Java program, I have a list of beans that I want to filter based on a specific property.

For example, say I have a list of Person, a JavaBean, where Person has

9条回答
  •  天命终不由人
    2020-12-01 07:00

    If you use a LinkedList(or any other collection which remove oprations is not very laborious) in single-threaded application the most efficacious solution is:

    final Iterator userIterator = users.iterator();
    while (userIterator.hasNext()) {
        if (/* your condition for exclusion */) {
            userIterator.remove();
        }
    }
    

提交回复
热议问题