Convert Iterable to List - Java java.util

Java examples for java.util:Iterable Convert

Description

Convert Iterable to List

Demo Code


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

import java.util.Iterator;

import java.util.List;

public class Main {
    public static <T> List<T> toList(final Iterable<T> iterable) {
        final List<T> list = new ArrayList<T>();
        for (Iterator<T> i = iterable.iterator(); i.hasNext();) {
            list.add(i.next());// ww w. jav a2  s .  c  om
        }
        return list;
    }
}

Related Tutorials