Java Collection Empty nullToEmpty(Collection coll)

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

Description

null To Empty

License

Open Source License

Return

given coll if it's not null, or an empty immutable otherwise.

Declaration

public static <U> Collection<U> nullToEmpty(Collection<U> coll) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2014 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* w ww  .  j  a  v  a2s .com*/
 *     Bruno Medeiros - initial implementation
 *******************************************************************************/

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

public class Main {
    /** @return given coll if it's not null, or an empty immutable {@link Collection} otherwise. */
    public static <U> Collection<U> nullToEmpty(Collection<U> coll) {
        return coll == null ? Collections.EMPTY_LIST : coll;
    }

    /** @return given coll if it's not null, or an empty immutable {@link Iterable} otherwise. */
    public static <E> Iterable<E> nullToEmpty(Iterable<E> coll) {
        return coll == null ? Collections.EMPTY_LIST : coll;
    }
}

Related

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