Here you can find the source of addToCollection(Collection
public static <T> List<T> addToCollection(Collection<T> collection, T obj)
//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; } }