Java String to List stringToBooleanList(final String str, final boolean[] listData)

Here you can find the source of stringToBooleanList(final String str, final boolean[] listData)

Description

Convert a string into an array of booleans.

License

Open Source License

Parameter

Parameter Description
str the input string
listData the output array

Declaration

public static void stringToBooleanList(final String str, final boolean[] listData) 

Method Source Code

//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;
            }
        }
    }
}

Related

  1. convertToList(String string, String delim)
  2. convertToList(String vars)
  3. convertToList(String[] array)
  4. stringsToList(final String[] src)
  5. stringToArrayList(String idString)
  6. stringToIntegerList(String input)
  7. stringToItems(List fontsList, boolean useSeparator)
  8. stringToList(final String string)
  9. stringToList(String content)