Here you can find the source of asList(final Iterator
Parameter | Description |
---|---|
T | a parameter |
iterator | the iterator. |
public static <T> List<T> asList(final Iterator<T> iterator)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { /**/*from w ww.j av a 2 s . co m*/ * Converts a given iterator in a list. * @param <T> * * @param iterator the iterator. * @return a list containing elements found in the iterator. */ public static <T> List<T> asList(final Iterator<T> iterator) { final List<T> result = new ArrayList<T>(); while (iterator.hasNext()) { result.add(iterator.next()); } return result; } }