Here you can find the source of count(byte[] array, byte value)
Parameter | Description |
---|---|
array | an array of bytes. |
value | a byte value. |
Parameter | Description |
---|---|
NullPointerException | if array==null. |
public static int count(byte[] array, byte value)
//package com.java2s; /*// w ww. j a va2 s . c o m * Copyright (C) 2014 Brian L. Browning * * This file is part of Beagle * * Beagle is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Beagle 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.concurrent.atomic.AtomicIntegerArray; public class Main { /** * Returns the number of the elements in the specified array that * equal the specified value. * @param array an array of bytes. * @param value a byte value. * @return the number of the elements in the specified array that * equal the specified value. * * @throws NullPointerException if {@code array==null}. */ public static int count(byte[] array, byte value) { int cnt = 0; for (byte i : array) { if (i == value) { ++cnt; } } return cnt; } /** * Returns the number of the elements in the specified array that * equal the specified value. * @param array an array of integers. * @param value an integer value. * @return the number of the elements in the specified array that * equal the specified value. * * @throws NullPointerException if {@code array==null}. */ public static int count(int[] array, int value) { int cnt = 0; for (int i : array) { if (i == value) { ++cnt; } } return cnt; } /** * Returns the number of the elements in the specified array that * equal the specified value. * @param array an array of floats. * @param value a float value. * @return the number of the elements in the specified array that * equal the specified value. * * @throws IllegalArgumentException if {@code Float.isNaN(value)==true} * @throws NullPointerException if {@code array==null} */ public static int count(float[] array, float value) { if (Float.isNaN(value)) { throw new IllegalArgumentException(String.valueOf(value)); } int cnt = 0; for (float f : array) { if (f == value) { ++cnt; } } return cnt; } /** * Returns the number of the elements in the specified array that * equal the specified value. * @param array an array of integers. * @param value an integer value. * @return the number of the elements in the specified array that * equal the specified value. * * @throws NullPointerException if {@code array==null} */ public static int count(AtomicIntegerArray array, int value) { int cnt = 0; for (int j = 0, n = array.length(); j < n; ++j) { if (array.get(j) == value) { ++cnt; } } return cnt; } }