Collections removeAll method

前端 未结 5 621

I would like to know if something like below is possible,

list.removeAll(namesToRemove)

I hope the context is understandable.

The

5条回答
  •  春和景丽
    2021-01-07 09:47

    You can do something like this using Google Collections Collections2.filter():

    final List namesToKeep = getNamesToFilter();
    List filtered = Collections2.filter(originalList, new Predicate() {
      @Override
      public boolean apply(MyObject o) {
        return namesToKeep.contains(o.getName());
      }
    });
    

提交回复
热议问题