Here you can find the source of count(Collection
public static <T> int count(Collection<T> ts, T toCount)
//package com.java2s; //License from project: BSD License import java.util.*; public class Main { public static <T> int count(Collection<T> ts, T toCount) { int out = 0; for (T t : ts) if (t.equals(toCount)) out++;/*from w w w .jav a 2s. c om*/ return out; } public static <T> int count(T[] ts, T toCount) { int out = 0; for (T t : ts) if (t.equals(toCount)) out++; return out; } public static int count(int[] is, int toCount) { int out = 0; for (int i : is) if (i == toCount) out++; return out; } public static int count(long[] ls, long toCount) { int out = 0; for (long l : ls) if (l == toCount) out++; return out; } }