Worked example
public static <T> int count(T[] arr, T target) {
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i].equals(target)) { // equals works for any object
count++;
}
}
return count;
}
String[] names = {"Ada", "Sam", "Ada"};
System.out.println(Util.count(names, "Ada")); // 2 — T inferred as String
The same method also counts Integers, or anything else — one method, every type.