Here you can find the source of addElement(T element, List
Parameter | Description |
---|---|
element | a parameter |
list | a parameter |
public static <T> List<T> addElement(T element, List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/* www. j av a 2 s. com*/ * @param element * @param list * @return */ public static <T> List<T> addElement(T element, List<T> list) { boolean exists = false; if (list == null) { list = new ArrayList<T>(2); } else { exists = list.contains(element); } if (!exists) list.add(element); return list; } }