Java Collection Empty nullToEmpty(Collection c)

Here you can find the source of nullToEmpty(Collection c)

Description

Returns either c or an empty collection if c is null .

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static <T> Collection<T> nullToEmpty(Collection<T> c) 

Method Source Code

//package com.java2s;
/*//from   w  w  w  . j a  v  a2s . co  m
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program 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,
 * version 2 of the License.
 *
 * This program 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 this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.util.Collection;
import java.util.Collections;

public class Main {
    /**
     * Returns either {@code c} or an empty collection if {@code c} is {@code null}.
     */
    @SuppressWarnings("unchecked")
    public static <T> Collection<T> nullToEmpty(Collection<T> c) {
        return (c == null ? (Collection<T>) Collections.emptyList() : c);
    }
}

Related

  1. nullOrEmpty(Collection coll)
  2. nullOrEmpty(Collection tested)
  3. nullOrEmpty(Collection c)
  4. nullOrEmpty(final Collection in)
  5. nullOrEmptyToDefault(final Collection collection, final Collection defaultValue)
  6. nullToEmpty(Collection coll)
  7. orEmpty(T collection)
  8. removeEmptyStrings(Collection data)
  9. safeIsEmpty(Collection collection)