Here you can find the source of toIntArray(boolean[] selectedValues)
public static int[] toIntArray(boolean[] selectedValues)
//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; } }