Java Integer Create toIntArray(boolean[] selectedValues)

Here you can find the source of toIntArray(boolean[] selectedValues)

Description

to Int Array

License

Eclipse Public License

Declaration

public static int[] toIntArray(boolean[] selectedValues) 

Method Source Code

//package com.java2s;
/* ******************************************************************************
 * // w  w w . java  2s. c  o  m
 * This file is part of JMH
 * 
 * License:
 *   EPL: http://www.eclipse.org/legal/epl-v10.html
 *   LGPL 3.0: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *   See the LICENSE file in the project's top-level directory for details.
 *
 * **************************************************************************** */

public class Main {
    public static int[] toIntArray(boolean[] selectedValues) {

        int numValues = 0;
        for (boolean value : selectedValues) {
            if (value) {
                numValues++;
            }
        }

        int[] intValues = new int[numValues];
        int numValue = 0;
        for (int i = 0; i < selectedValues.length; i++) {
            if (selectedValues[i]) {
                intValues[numValue] = i;
                numValue++;
            }
        }
        return intValues;
    }
}

Related

  1. toInt32(Object prmIntObject)
  2. toInt4Trim(String value, int _default)
  3. toIntA(byte[] data)
  4. toIntArr(String s, String split)
  5. toIntArray(boolean[] array)
  6. toIntArray(byte[] byteArray)
  7. toIntArray(byte[] bytes)
  8. toIntArray(byte[] data)
  9. toIntArray(byte[] data)