Java List Remove Null Value removeNulls(final List list)

Here you can find the source of removeNulls(final List list)

Description

Removes all null elements from list.

License

Open Source License

Parameter

Parameter Description
list list to refactor
T list type

Return

refactored list

Declaration

public static <T> List<T> removeNulls(final List<T> list) 

Method Source Code


//package com.java2s;
/*//from w w w .j  ava  2  s. c o  m
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.*;

public class Main {
    /**
     * Removes all null elements from list.
     *
     * @param list list to refactor
     * @param <T>  list type
     * @return refactored list
     */
    public static <T> List<T> removeNulls(final List<T> list) {
        if (list == null) {
            return null;
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            if (list.get(i) == null) {
                list.remove(i);
            }
        }
        return list;
    }
}

Related

  1. removeNullAndDuplicates(List list)
  2. removeNullElement(List source)
  3. removeNullElements(List list)
  4. removeNullFromList(List list)
  5. removeNulls(Collection list)
  6. removeNulls(List values)
  7. removeNulls(List list)
  8. removeNulls(List values)
  9. removeNullValues(List targetValues, List> argumentValues)