float Array to Json - Android File Input Output

Android examples for File Input Output:Json

Description

float Array to Json

Demo Code


//package com.java2s;

public class Main {
    static String floatArray2Json(final float[] array) {
        if (array.length == 0) {
            return "[]";
        }//w  w w  . j a v a2  s.co  m
        final StringBuilder sb = new StringBuilder(array.length << 4);
        sb.append('[');
        for (final float o : array) {
            sb.append(Float.toString(o));
            sb.append(',');
        }
        // set last ',' to ']':
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}

Related Tutorials