Here you can find the source of addToList(List
Parameter | Description |
---|---|
T | the generic type |
list | the list |
value | the value |
public static <T> List<T> addToList(List<T> list, T value)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/*from w w w . j av a2 s . c o m*/ * Check and adds elements to list (create new ArrayList if list is null) * * @param <T> * the generic type * @param list * the list * @param value * the value * @return the list (if list is null, create new array list) */ public static <T> List<T> addToList(List<T> list, T value) { if (value == null) return list; if (list == null) list = new ArrayList<T>(); list.add(value); return list; } }