Here you can find the source of stringToBooleanList(final String str, final boolean[] listData)
Parameter | Description |
---|---|
str | the input string |
listData | the output array |
public static void stringToBooleanList(final String str, final boolean[] listData)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w . ja va2 s.co m*/ * Convert a string into an array of booleans. * * @param str the input string * @param listData the output array */ public static void stringToBooleanList(final String str, final boolean[] listData) { // Check the input for a null or empty string, or no 1's if ((str == null) || (str.length() < 1) || (str.indexOf('1') < 0)) { // Fill the array with false java.util.Arrays.fill(listData, false); return; } // Iterate over the string final int len = str.length(); for (int i = 0; i < 6; ++i) { // Check if we're before the end of the string if (i < len) { // We are, so convert the character into a boolean listData[i] = (str.charAt(i) == '1'); } else { // We're past the end of the array, so assume false listData[i] = false; } } } }