counts the number of occurrences of the passed value in the passed array - Android java.lang

Android examples for java.lang:Array Element

Description

counts the number of occurrences of the passed value in the passed array

Demo Code


//package com.java2s;

public class Main {
    /**// ww w . ja v  a2  s. co  m
     * counts the number of occurrences of the passed value in the passed array
     * @param _arr the array to count the occurrences
     * @param _value the value to count
     * @return the number of occurrences of the passed value in the passed array
     */
     static int countOccurrence(double[] _arr, double _value) {
        int res = 0;
        for (double d : _arr) {
            if (d == _value) {
                res++;
            }
        }
        return res;
    }
}

Related Tutorials