Returns a collection containing all elements of the iterator. - Android java.util

Android examples for java.util:Collection Contains

Description

Returns a collection containing all elements of the iterator.

Demo Code

// Copyright (c) 2003-present, Jodd Team (jodd.org). All Rights Reserved.
//package com.book2s;
import java.util.ArrayList;
import java.util.Collection;

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

public class Main {
    public static void main(String[] argv) {
        Iterator iterator = java.util.Arrays.asList("asdf", "book2s.com")
                .iterator();/*from www  .  j a v a2  s .  co  m*/
        System.out.println(asCollection(iterator));
    }

    /**
     * Returns a collection containing all elements of the iterator.
     */
    public static <T> Collection<T> asCollection(
            final Iterator<? extends T> iterator) {
        List<T> list = new ArrayList<T>();
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }
}

Related Tutorials