Java Collection Add addToCollection(Collection collection, T obj)

Here you can find the source of addToCollection(Collection collection, T obj)

Description

add To Collection

License

Open Source License

Declaration

public static <T> List<T> addToCollection(Collection<T> collection,
        T obj) 

Method Source Code

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

import java.util.*;

public class Main {

    public static <T> List<T> addToCollection(Collection<T> collection,
            T obj) {//from  w  w  w . j a  va2 s . com
        List<T> list = null;

        if (null == collection) {
            list = new ArrayList<>();
            list.add(obj);
        } else {
            collection.add(obj);
        }

        return list;
    }
}

Related

  1. addTo(Collection l, Object... os)
  2. addTo(E element, C collection)
  3. addTo(Map> map, K key, V value)
  4. addToCollection(C collection, E... elements)
  5. addToCollection(Collection collection, final T value)
  6. addToCollection(Collection theCollection, T... objects)
  7. addToCollection(Iterator iterator, Collection collection)
  8. addToCollection(T dest, boolean failOnNull, Iterable... srcs)
  9. addToCollectionIfNotNull(Collection collection, Object value)