集合空元素的处理,api 有直接处理的方法,使用的是迭代器,本质上还是 for 循环的思想
public static <T> List<T> removeNull(List<? extends T> oldList) { // 你没有看错,真的是有 1 行代码就实现了 oldList.removeAll(Collections.singleton(null)); return (List<T>) oldList; }
//去除null值 if (f.getParticularsList().size()!=0){ List<AmountDetailParticulars> list1 = removeNull(f.getParticularsList()); f.setParticularsList(list1); }