Java List Remove Null Value removeNulls(List values)

Here you can find the source of removeNulls(List values)

Description

Creates a new list which contains all the non-null elements of the given list.

License

Open Source License

Parameter

Parameter Description
T the type of the parameter list and the resulting list
values the list to be processed

Return

the same values except nulls

Declaration

public static <T> List<T> removeNulls(List<T> values) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from w ww.  j a va 2 s  . c  om
     * Creates a new list which contains all the non-null elements of the given list.
     * @param <T> the type of the parameter list and the resulting list 
     * @param values the list to be processed
     * @return the same values except nulls
     */
    public static <T> List<T> removeNulls(List<T> values) {
        List<T> result = new ArrayList<>();
        for (T value : values) {
            if (value != null) {
                result.add(value);
            }
        }
        return result;
    }
}

Related

  1. removeNullFromList(List list)
  2. removeNulls(Collection list)
  3. removeNulls(final List list)
  4. removeNulls(List values)
  5. removeNulls(List list)
  6. removeNullValues(List targetValues, List> argumentValues)