1.移除List<String>中指定元素
for(int i = assSupplementList.size() - 1; i >= 0; i--) { TypgHouseOrderAssessmentSupplement item = assSupplementList.get(i); if (item.getBzx().contains("新建房屋")) { assSupplementList.remove(item); } }
2.移除List<对象>中指定元素
Iterator<TypgHouseOrderAssessmentSupplement> iterator = assSupplementList.iterator(); while(iterator.hasNext()) { TypgHouseOrderAssessmentSupplement item = iterator.next(); if (item.getBzx().contains("新建房屋")) { iterator.remove(); } }
3、使用Java8中的lambda表达式过滤
//从list中过滤出,list字段中不包含某个字符串的数据 //list的yourStr字段的值:“aaa,bbb,ccc”,XXArr()属性的值是:“aaa,ccc” List<YourBean> list = xxService.findList(yourBean); for (String index : beanName.getXXArr()) { list = list.stream().filter(item -> item.getYourStr().indexOf(index) < 0).collect(Collectors.toList()); } return list;
标签:iterator,List,list,assSupplementList,item,移除,Java8 From: https://www.cnblogs.com/Fooo/p/17441878.html