int Array to Json String - Android File Input Output

Android examples for File Input Output:Json String

Description

int Array to Json String

Demo Code


//package com.java2s;

public class Main {
    static String intArray2Json(final int[] array) {
        if (array.length == 0) {
            return "[]";
        }//from   w  w w .ja  va  2 s .c om
        final StringBuilder sb = new StringBuilder(array.length << 4);
        sb.append('[');
        for (final int o : array) {
            sb.append(Integer.toString(o));
            sb.append(',');
        }
        // set last ',' to ']':
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}

Related Tutorials