获取一个数组,并计算其元素中有多少与该参数相等
/* 来自 N o w J a v a . c o m*/ //package com.nowjava; public class Main { /** * Takes an array and counts how many of its elements equals with the * parameter * * @param <T> Type * @param typeClass the class of the type of the array * @param array the array you want to operate on * @param element the element you want to check * @return how many times the element exists in the array */ public static <T> int contains(Class<T> typeClass, T[] array, T element) { int counter = 0; for (T t : array) { if (t.equals(element)) {