Java List from listOf(Iterable it)

Here you can find the source of listOf(Iterable it)

Description

Returns a list form the the specified Iterable .

License

Apache License

Declaration

public static <T> List<T> listOf(Iterable<T> it) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

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

public class Main {
    /**//from   www  .j  a v a2s .c  om
     * Returns a list form the the specified {@link Iterable}.
     * If the specified {@link Iterable} is yet a {@link List} than it
     * is returned as is, otherwise a brand new {@link List} is created.
     */
    public static <T> List<T> listOf(Iterable<T> it) {
        if (it instanceof List) {
            return (List<T>) it;
        }
        final List<T> result = new LinkedList<T>();
        for (final T t : it) {
            result.add(t);

        }
        return result;
    }

    /**
     * @see #listOf(Iterable)
     */
    public static <T> List<T> listOf(T... items) {
        return Arrays.asList(items);
    }
}

Related

  1. listOf(Collection collection, T... elements)
  2. listOf(Collection... elts)
  3. listOf(double... values)
  4. listOf(E... elements)
  5. listOf(E... elements)
  6. listOf(String type)
  7. listOf(T value, int size)
  8. listOf(T... args)
  9. listOf(T... elements)