Create new Array List from Iterable<E> - Java java.util

Java examples for java.util:Iterable Convert

Description

Create new Array List from Iterable<E>

Demo Code


//package com.java2s;
import java.util.ArrayList;

import java.util.Iterator;

public class Main {
    public static <E> ArrayList<E> newArrayList(Iterable<E> iterable) {
        if (iterable == null) {
            throw new NullPointerException();
        }/*from  w  ww .  j  ava  2s. c  o  m*/
        ArrayList<E> list = new ArrayList<E>();
        for (Iterator<E> i = iterable.iterator(); i.hasNext();) {
            list.add(i.next());
        }
        return list;
    }
}

Related Tutorials