short Array to Json String - Android File Input Output

Android examples for File Input Output:Json String

Description

short Array to Json String

Demo Code


//package com.java2s;

public class Main {
    static String shortArray2Json(final short[] array) {
        if (array.length == 0) {
            return "[]";
        }/*ww w. j  av  a  2s .  com*/
        final StringBuilder sb = new StringBuilder(array.length << 4);
        sb.append('[');
        for (final short o : array) {
            sb.append(Short.toString(o));
            sb.append(',');
        }
        // set last ',' to ']':
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}

Related Tutorials