Java List from Array asList(final Iterable iterable)

Here you can find the source of asList(final Iterable iterable)

Description

as List

License

Open Source License

Declaration

public static <T> List<T> asList(final Iterable<? extends T> iterable) 

Method Source Code


//package com.java2s;
/*/*www .j ava 2 s  . c  om*/
 * Copyright (C) 2013
 *
 * 52?North Initiative for Geospatial Open Source Software GmbH
 * Contact: Andreas Wytzisk
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * 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
 */

import java.util.ArrayList;

import java.util.Collection;
import java.util.Collections;

import java.util.LinkedList;
import java.util.List;

public class Main {
    public static <T> List<T> asList(final Iterable<? extends T> iterable) {
        return (iterable instanceof Collection) ? new LinkedList<T>((Collection<? extends T>) iterable)
                : new LinkedList<T>() {
                    private static final long serialVersionUID = 3109256773218160485L;
                    {
                        if (iterable != null) {
                            for (final T t : iterable) {
                                add(t);
                            }
                        }
                    }
                };
    }

    public static <T> List<T> asList(final T t, final T... ts) {
        final ArrayList<T> list = new ArrayList<T>(ts.length + 1);
        list.add(t);
        Collections.addAll(list, ts);
        return list;
    }
}

Related

  1. asList(final Collection c)
  2. asList(final E... array)
  3. asList(final int... values)
  4. asList(final int[] a)
  5. asList(final int[] a)
  6. asList(final Iterable iterable)
  7. asList(final long[] ids)
  8. asList(final Object array)
  9. asList(final Object[] arguments)