public static < E > int search ( E [ ] array , E value , int occurrence ) { if ( occurrence <= 0 ) { throw new IllegalArgumentException ( "Occurrence must be greater or equal to 1 and less than " + "the array length: " + occurrence ) ; } int valuesSeen = 0 ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( array [ i ] == value ) { valuesSeen ++ ; if ( valuesSeen == occurrence ) { return i ; } } } return - 1 ; }
Search for the value in the array and return the index of the specified occurrence from the beginning of the array .