Turns a string into a float array. - Android java.lang

Android examples for java.lang:String Parse

Description

Turns a string into a float array.

Demo Code


//package com.java2s;

public class Main {
    /**//from   w w  w. j  a v  a2s  .  c o m
     * Turns a string into a float array.
     * 'spaces' must only contain string equivalent of valid floats separated with commas
     * with no spaces.
     * @param string
     * @return a float array
     */
    public static float[] stringToFloatArray(String string) {
        String strArray[] = string.split(",");
        int length = strArray.length;
        float floatArray[] = new float[length];
        int i = 0;
        for (String str : strArray) {
            floatArray[i] = Float.parseFloat(str);
            i++;
        }
        return floatArray;
    }
}

Related Tutorials