Java Array From toArray(CharSequence input)

Here you can find the source of toArray(CharSequence input)

Description

Translates a String of zero ('0') and one ('1') characters to an array of boolean.

License

LGPL

Parameter

Parameter Description
input a <code>String</code> made up of '1' and '0' characters.

Return

an array of boolean values which is equivalent to the input String.

Declaration

public static boolean[] toArray(CharSequence input) 

Method Source Code

//package com.java2s;
/*//from  w  w w. j av  a2 s.c  o  m
 * Copyright 2007-2013
 * Licensed under GNU Lesser General Public License
 * 
 * This file is part of EpochX: genetic programming software for research
 * 
 * EpochX is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * EpochX is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with EpochX. If not, see <http://www.gnu.org/licenses/>.
 * 
 * The latest version is available from: http://www.epochx.org
 */

public class Main {
    /**
     * Translates a <code>String</code> of zero ('0') and one ('1') characters
     * to an array of <code>boolean</code>. <code>0</code> characters are
     * translated to a <code>false</code> value, and <code>1</code> characters
     * to <code>true</code> value.
     *
     * @param input a <code>String</code> made up of '1' and '0' characters.
     * @return an array of <code>boolean</code> values which is equivalent to
     * the input <code>String</code>.
     */
    public static boolean[] toArray(CharSequence input) {
        int len = input.length();
        boolean[] bools = new boolean[len];

        for (int i = 0; i < len; i++) {
            bools[i] = (input.charAt(i) == '1');
        }

        return bools;
    }
}

Related

  1. arrayFromList(String aList)
  2. arrayFromString(String fromString)
  3. arrayFromString(String s)
  4. arrayFromString(String str)
  5. toArray(boolean[] array)
  6. toArray(Class interfaceClass)
  7. toArray(Double[] array)
  8. toArray(E[] o)
  9. toArray(final double d)