Java:删除所有ArrayList <pojo>

时间:2016-11-20 21:14:20

标签: java list arraylist iteration filtering

全部,   我试图弄清楚删除包含CSV信息的List中的项目最有效的方法。我想使用removeAll(),但我不确定如何将其应用于这种情况。

以下面的代码为例

示例数据:

Property 1 | Property 2 | Property 3
Foo        | Bar        | Data
Foo1       | Bar        | Data
Foo        | Bar1       | Data

示例POJO

public class MyPOJO {
  private String property1;
  private String property2;
  private String property3;

  public String getProperty1(){return property1;}
  public String getProperty2(){return property2;}
  public String getProperty3(){return property3;}
  public void   setProperty1(String property1){this.property1 = property1;}
  public void   setProperty2(String property1){this.property2 = property2;}
  public void   setProperty3(String property1){this.property3 = property3;}
}

稍后,我将一些CSV解析为此POJO并通过HashMap接收一组过滤器,如下所示

public class MyPOJOParser() {
  private List<MyPOJO> myPOJO = new ArrayList<MyPOJO>();

  public myPOJOParser(String flatfile, Map<String, String> filters) {
    myPOJO = parse(flatfile);  // Returns List<MyPOJO> 
  }
}

如何使用上述示例执行以下操作

// filters contains 2 key value pairs:
// Property1,Foo1
// Property2,Bar
filters.forEach((k,v)->{
  // if(Property1 == "Foo1" && Property2 == "Bar") then remove all occurrences of this
});

0 个答案:

没有答案