Guava - How to remove from a list, based on a predicate, keeping track of what was removed?

后端 未结 5 1631
清酒与你
清酒与你 2021-02-07 06:51

I have an ArrayList to be filtered, and various Guava Predicates to filter it with. This list will have only 50-100 elements.

I was planning on

5条回答
  •  花落未央
    2021-02-07 07:33

    I guess you need:

    Predicate predicate1 = new Predicate(){  
        @Override  
        public boolean apply(XXX input) {  
            if(...) //satisfy your filter
                return true;  
            else  
                return false;  
    }};  
    
    Predicate predicate2 = new Predicate(){  
        @Override  
        public boolean apply(XXX input) {  
            if(...) //satisfy your filter
                return true;  
            else  
                return false;  
    }};
    Predicate allPredicates = Predicates.and(predicate1, predicate2);
    //or Predicates.or(predicate1, predicate2);
    
    Collection list2 = Collections2.filter(list, allPredicates); 
    

提交回复
热议问题