List<String> list = new ArrayList<String>();
list.add("One");
list.add(null);
list.add("Two!");
list.add(null);
list.add("Three");
list.add(null);
list.add("Four");
list.add(null);
我有一个包含 null 元素的列表。有什么方法可以在不使用任何迭代的情况下从当前集合中删除 null 元素?
最佳答案
这应该可行:
list.removeAll(Collections.singleton(null));
关于java - 从列表中删除空元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8559257/