Java List from Array asList(float[] elements)

Here you can find the source of asList(float[] elements)

Description

Converts an array of float numbers to a list of Float s.

License

Open Source License

Parameter

Parameter Description
elements Array of float numbers.

Return

A list with all numbers as Float .

Declaration

public static List<Float> asList(float[] elements) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .ja  v a 2s .c  o m*/
 * VectorGraphics2D: Vector export for Java(R) Graphics2D
 *
 * (C) Copyright 2010-2016 Erich Seifert <dev[at]erichseifert.de>
 *
 * This file is part of VectorGraphics2D.
 *
 * VectorGraphics2D is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VectorGraphics2D is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with VectorGraphics2D.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Converts an array of {@code float} numbers to a list of {@code Float}s.
     * The list will be empty if the array is empty or {@code null}.
     * @param elements Array of float numbers.
     * @return A list with all numbers as {@code Float}.
     */
    public static List<Float> asList(float[] elements) {
        int size = (elements != null) ? elements.length : 0;
        List<Float> list = new ArrayList<Float>(size);
        if (elements != null) {
            for (Float elem : elements) {
                list.add(elem);
            }
        }
        return list;
    }

    /**
     * Converts an array of {@code double} numbers to a list of {@code Double}s.
     * The list will be empty if the array is empty or {@code null}.
     * @param elements Array of double numbers.
     * @return A list with all numbers as {@code Double}.
     */
    public static List<Double> asList(double[] elements) {
        int size = (elements != null) ? elements.length : 0;
        List<Double> list = new ArrayList<Double>(size);
        if (elements != null) {
            for (Double elem : elements) {
                list.add(elem);
            }
        }
        return list;
    }
}

Related

  1. asList(final T... array)
  2. asList(final T... data)
  3. asList(final T... data)
  4. asList(final T[] array)
  5. asList(final T[] input)
  6. asList(int... array)
  7. asList(int... data)
  8. asList(int... values)
  9. asList(int[] a)