Java Float Array Create toFloatArray(String[] anArray)

Here you can find the source of toFloatArray(String[] anArray)

Description

to Float Array

License

Open Source License

Parameter

Parameter Description
anArray The array to convert.

Exception

Parameter Description
NumberFormatException if any of the input elements can not beparsed as a float.

Return

An array of floats of the same length as the input, each element of which contains the decoded float of the corresponding input element.

Declaration

public static float[] toFloatArray(String[] anArray) throws NumberFormatException 

Method Source Code

//package com.java2s;
/*/*  www  .  j av  a  2s .  c o m*/
 * ArrayUtilities.java (Class: com.madphysicist.tools.util.ArrayUtilities)
 *
 * Mad Physicist JTools Project (General Purpose Utilities)
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 by Joseph Fox-Rabinovitz
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

public class Main {
    /**
     * @brief Converts an array of strings into an array of floats.
     *
     * The strings are expected to be in base ten.
     *
     * @param anArray The array to convert.
     * @return An array of floats of the same length as the input, each element
     * of which contains the decoded float of the corresponding input element.
     * @throws NumberFormatException if any of the input elements can not be
     * parsed as a float.
     * @since 1.0.2
     */
    public static float[] toFloatArray(String[] anArray) throws NumberFormatException {
        float[] output = new float[anArray.length];
        for (int index = 0; index < anArray.length; index++)
            output[index] = Float.parseFloat(anArray[index]);
        return output;
    }
}

Related

  1. toFloatArray(Float[] data)
  2. toFloatArray(Number[] array)
  3. toFloatArray(Object[] arr)
  4. toFloatArray(String str, String separator)
  5. toFloatArray(String text, String delim)
  6. toFloatArrays(double[][] arrays)
  7. toFloatByObject(Object obj)
  8. toFloatMatrix(int[][] m)
  9. toFloatRawBits(int i)