Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> List<T> addToList(List<T> list, T a) { List<T> newlist = newEmptyList(); newlist.addAll(list); newlist.add(a); return newlist; } public static <T> List<T> newEmptyList() { return new ArrayList<>(); } public static <T> List<T> add(List<T> list, T a) { List<T> newList = newEmptyList(); newList.addAll(list); newList.add(a); return newList; } }