Java List from Array asList(T firstItem, T... otherItems)

Here you can find the source of asList(T firstItem, T... otherItems)

Description

as List

License

LGPL

Declaration

@SafeVarargs
    public static <T> List<T> asList(T firstItem, T... otherItems) 

Method Source Code


//package com.java2s;
/*//ww w  .  jav a2s  . co  m
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
 */

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

public class Main {
    @SafeVarargs
    public static <T> List<T> asList(T firstItem, T... otherItems) {
        List<T> list = new ArrayList<>(otherItems.length + 1);
        list.add(firstItem);
        Collections.addAll(list, otherItems);
        return list;
    }
}

Related

  1. asList(String val)
  2. asList(String valuesSeparatedBy, String delimiter)
  3. asList(String... args)
  4. asList(String... strings)
  5. asList(T element)
  6. asList(T... a)
  7. asList(T... a)
  8. asList(T... a)
  9. asList(T... a)