Java Iterator to List toList(Iterator iterator)

Here you can find the source of toList(Iterator iterator)

Description

to List

License

Open Source License

Declaration

public static List<?> toList(Iterator<?> iterator) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

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

public class Main {
    /**/*  w  w w .j a v  a 2 s  .  com*/
     * @param selection
     * @return
     */
    public static List<?> toList(Object[] objs) {
        ArrayList<Object> ret = new ArrayList<Object>();
        if (objs != null)
            for (int i = 0; i < objs.length; i++)
                ret.add(objs[i]);
        return ret;
    }

    /**
     * @param selection
     * @return
     */
    public static List<Integer> toList(int[] objs) {
        List<Integer> ret = new ArrayList<Integer>();
        if (objs != null)
            for (int i = 0; i < objs.length; i++)
                ret.add(objs[i]);
        return ret;
    }

    public static List<?> toList(Iterator<?> iterator) {
        ArrayList<Object> ret = new ArrayList<Object>();
        while (iterator.hasNext())
            ret.add(iterator.next());
        return ret;
    }
}

Related

  1. toList(Iterator iterator)
  2. toList(Iterator src)
  3. toList(Iterator iterator)
  4. toList(Iterator it)
  5. toList(Iterator iter)