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

方法一、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();
    }
}

posted on 2018-08-20 10:45  小破孩楼主  阅读(29268)  评论(0编辑  收藏  举报