方法一
public static void removeByIterator(List<String> list) {
Iterator it = list.iterator();
while (it.hasNext()) {
if (it.next() == null) {
it.remove();
}
}
}
方法二
public static void removeByRemoveAll(List<String> list) {
List<String> remove = new ArrayList<>();
remove.add(null);
list.removeAll(remove);
}
方法三
public static void removeBySingleton(List<String> list) {
list.removeAll(Collections.singleton(null));
}
方法四
public static List removeByStream(List<String> list) {
List<String> collect = list.stream().filter(Objects::nonNull).collect(Collectors.toList());
return collect;
}