Java Iterable to List toList(Iterable it)

Here you can find the source of toList(Iterable it)

Description

to List

License

Apache License

Declaration

public static <T> ArrayList<T> toList(Iterable<T> it) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    public static ArrayList<Double> toList(double[] xs) {
        ArrayList<Double> list = new ArrayList();
        for (double x : xs)
            list.add(x);/*from   w  ww.ja  va 2s  . co  m*/
        return list;
    }

    public static <T> ArrayList<T> toList(Iterable<T> it) {
        if (it instanceof ArrayList)
            return (ArrayList) it;
        ArrayList<T> list = new ArrayList<T>();
        for (T x : it)
            list.add(x);
        return list;
    }

    public static double[] add(double[] v1, double[] v2) {
        double[] sumv = new double[v1.length];
        for (int i = 0; i < v1.length; i++)
            sumv[i] = v1[i] + v2[i];
        return sumv;
    }

    public static double[] add(double[] v1, int[] v2) {
        double[] sumv = new double[v1.length];
        for (int i = 0; i < v1.length; i++)
            sumv[i] = v1[i] + v2[i];
        return sumv;
    }

    public static double[] add(double[] v1, double x) {
        double[] sumv = new double[v1.length];
        for (int i = 0; i < v1.length; i++)
            sumv[i] = v1[i] + x;
        return sumv;
    }
}

Related

  1. toList(Iterable iter)
  2. toList(Iterable values)
  3. toList(Iterable protocols)
  4. toList(Iterable elements)
  5. ToList(Iterable inList)
  6. toList(Iterable items)
  7. toList(Iterable iter)
  8. toList(Iterable iterable)
  9. toList(Iterable iterable)