double Array to Json - Android File Input Output

Android examples for File Input Output:Json

Description

double Array to Json

Demo Code


//package com.java2s;

public class Main {
    static String doubleArray2Json(final double[] array) {
        if (array.length == 0) {
            return "[]";
        }//from www.j a  v a 2  s .  c o  m
        final StringBuilder sb = new StringBuilder(array.length << 4);
        sb.append('[');
        for (final double o : array) {
            sb.append(Double.toString(o));
            sb.append(',');
        }
        // set last ',' to ']':
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}

Related Tutorials