Here you can find the source of addIfNotNull(List
Parameter | Description |
---|---|
l | The list to add to. |
o | The element to add. |
public static <T> List<T> addIfNotNull(List<T> l, T o)
//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; } }