JAVA List中剔除空元素(null)的方法

来源:互联网 发布:虚拟机网络配置 编辑:程序博客网 时间:2024/06/10 22:11

方法一:

list.removeAll(Collections.singleton(null));

方法二:

List nullList = new ArrayList();nullList.add(null);list.removeAll(nullList);


方法三:

Iterator it = list.iterator();while (it.hasNext()) {if (it.next() == null) {it.remove();}}


0 0