boolean Array to Json String - Android File Input Output

Android examples for File Input Output:Json String

Description

boolean Array to Json String

Demo Code


//package com.java2s;

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

Related Tutorials