Here you can find the source of removeNullElement(List source)
Parameter | Description |
---|---|
source | a parameter |
public static List removeNullElement(List source)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { /**/* w ww. ja v a2 s .c o m*/ * Removes all of the 'null' elements in a list, recursively. * * @param source * @return source - java.util.List */ public static List removeNullElement(List source) { if (!containsNullElement(source)) return source; while (source.contains(null)) { source.remove(null); } return source; } /** * Checks whether 'list' has any null element in it. 1- if list itself is * null, return false 2- if list is empty, return false 3- if list contains * any null element, return true Note: Return true on first instance of * finding null element * * @param source * @return boolean */ public static boolean containsNullElement(List source) { if (source == null) return false; if (source.isEmpty()) return false; if (source.contains(null)) return true; return false; } }