Java List from Array asList(Iterable iterable)

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

Description

as List

License

Open Source License

Declaration

public static <T> List<T> asList(Iterable<T> iterable) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2012 Nikita Zhiltsov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html//from w w w .  j  a v a  2s  . c  om
 * 
 * Contributors:
 *     Nikita Zhiltsov - initial API and implementation
 *     Azat Khasanshin - implementation
 ******************************************************************************/

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class Main {
    public static <T> List<T> asList(Iterable<T> iterable) {
        List<T> list = new ArrayList<T>();
        Iterator<T> it = iterable.iterator();
        while (it.hasNext()) {
            T element = it.next();
            if (element != null) {
                list.add(element);
            }
        }
        return list;
    }
}

Related

  1. asList(int[] list)
  2. asList(int[] values)
  3. asList(Iterable iterable)
  4. asList(Iterable iterable)
  5. asList(Iterable iterable)
  6. asList(Iterator iterator)
  7. asList(List list)
  8. asList(long... array)
  9. asList(Object info)