Convert Iterator to List - Java java.util

Java examples for java.util:List Convert

Description

Convert Iterator to List

Demo Code


//package com.book2s;
import java.util.*;

public class Main {
    public static void main(String[] argv) {
        Iterator ite = java.util.Arrays.asList("asdf", "book2s.com")
                .iterator();//  www  .  j av  a 2s  .c  om
        System.out.println(list(ite));
    }

    public static List list(Iterator ite) {
        ArrayList ret = new ArrayList();
        while (ite.hasNext()) {
            Object o = ite.next();
            ret.add(o);
        }
        return ret;
    }
}

Related Tutorials