Java Iterator convertToArray(Iterator iter)

Here you can find the source of convertToArray(Iterator iter)

Description

convert To Array

License

Open Source License

Declaration

public static double[] convertToArray(Iterator<Double> iter) 

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 {
    public static double[] convertToArray(Iterator<Double> iter) {
        return listToArray(convertToList(iter));
    }/* w  w  w.  j  a  va  2  s.  c  o m*/

    private static double[] listToArray(List<Double> list) {
        double[] arr = new double[list.size()];
        for (int i = 0; i < list.size(); ++i)
            arr[i] = list.get(i);
        return arr;
    }

    public static List<Double> convertToList(Iterator<Double> iter) {
        List<Double> list = new ArrayList<Double>();
        while (iter.hasNext())
            list.add(iter.next());
        return list;
    }
}

Related

  1. concatLines(Iterator lineIterator)
  2. contains(final Iterator iter, final E item)
  3. contains(Iterator it, T o)
  4. contains(Iterator iterator, Object element)
  5. contains(Iterator iterator, String value)
  6. convertToList(Iterator iter)
  7. copy(Iterator iterator)
  8. copyIterator(Iterable iterable)
  9. copyIterator(Iterator iter)