Java List Null Empty addIfNotNull(List l, T o)

Here you can find the source of addIfNotNull(List l, T o)

Description

Add a value to a list if the value is not null.

License

Apache License

Parameter

Parameter Description
l The list to add to.
o The element to add.

Return

The same list.

Declaration

public static <T> List<T> addIfNotNull(List<T> l, T o) 

Method Source Code


//package com.java2s;
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *

import java.util.*;

public class Main {
    /**/*  w  w  w  .j  a va  2s. co  m*/
     * Add a value to a list if the value is not null.
     *
     * @param l The list to add to.
     * @param o The element to add.
     * @return The same list.
     */
    public static <T> List<T> addIfNotNull(List<T> l, T o) {
        if (o != null)
            l.add(o);
        return l;
    }
}

Related

  1. addAllExceptNullValue(List list, V[] values)
  2. addAllIfAllValuesNotNull(List list, V[] values)
  3. addIfNotNull(final List list, final T value)
  4. addIfValueNotNull(List list, V value)
  5. addIgnoreNull(final List list, final T... objects)
  6. addListNotNullValue(List sourceList, V value)
  7. addNonEmpty(List list, String value)