Java List Join join(T element, List otherElements)

Here you can find the source of join(T element, List otherElements)

Description

Joins all given elements in a single (flat) List.

License

Open Source License

Parameter

Parameter Description
element first element to include in the list
otherElements other elements to include in the list
T the elements type

Return

a list combining all given elements

Declaration

public static <T> List<T> join(T element, List<T> otherElements) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014, 2015 Red Hat. All rights reserved. This program and the accompanying
 * materials are made available under the terms of the Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Red Hat - Initial Contribution
 *******************************************************************************/

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from  w w w .  j a v a2  s  .c o  m
     * Joins all given elements in a single (flat) List.
     * 
     * @param element first element to include in the list
     * @param otherElements other elements to include in the list
     * @param <T> the elements type
     * @return a list combining all given elements
     */
    public static <T> List<T> join(T element, List<T> otherElements) {
        final List<T> result = new ArrayList<>();
        result.add(element);
        result.addAll(otherElements);
        return result;
    }
}

Related

  1. join(String separator, List parts)
  2. join(String sign, List src)
  3. join(String[] elementList, String separator)
  4. join(String[] list, String separator)
  5. join(T delimiter, List list)
  6. joinAndQuote(char joinChar, char quoteChar, List strings)
  7. joinArray(List list, String separator)
  8. joinArrayString(List values)
  9. joinColumnArray(List columnArray)