Here you can find the source of join(List extends T> list, T element)
Parameter | Description |
---|---|
list | The list of elements to be appended first. |
element | The additional element. |
T | The list's generic type. |
public static <T> List<T> join(List<? extends T> list, T element)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*w w w . jav a2s . c o m*/ * Creates a list that contains all elements of a given list with an additional appended element. * * @param list The list of elements to be appended first. * @param element The additional element. * @param <T> The list's generic type. * @return An {@link java.util.ArrayList} containing all elements. */ public static <T> List<T> join(List<? extends T> list, T element) { List<T> result = new ArrayList<T>(list.size() + 1); result.addAll(list); result.add(element); return result; } /** * Creates a list that contains all elements of a given list with an additional prepended element. * * @param list The list of elements to be appended last. * @param element The additional element. * @param <T> The list's generic type. * @return An {@link java.util.ArrayList} containing all elements. */ public static <T> List<T> join(T element, List<? extends T> list) { List<T> result = new ArrayList<T>(list.size() + 1); result.add(element); result.addAll(list); return result; } /** * Joins two lists. * * @param leftList The left list. * @param rightList The right list. * @param <T> The most specific common type of both lists. * @return A combination of both lists. */ public static <T> List<T> join(List<? extends T> leftList, List<? extends T> rightList) { List<T> result = new ArrayList<T>(leftList.size() + rightList.size()); result.addAll(leftList); result.addAll(rightList); return result; } }