CollectionUtils { public static int getLengthOfCollection(Object value) { if (isArray(value.getClass())) { return Array.getLength(value); } else { return ((Collection<?>)value).size(); } } private  CollectionUtils(); static boolean isArray(Class<?> aClass); static boolean isCollection(Class<?> aClass); static boolean isList(Class<?> aClass); static boolean isSet(Class<?> aClass); static boolean isPrimitiveArray(Class<?> aClass); static int getLengthOfCollection(Object value); static Object getValueFromCollection(Object collection, int index); static Set<?> createNewSet(Class<T> destType); static Set<?> createNewSet(Class<T> destSetType, Collection<?> srcValue); static Object convertListToArray(List<T> list, Class<T> destEntryType); static List<Object> convertPrimitiveArrayToList(Object primitiveArray); static Set<E> intersection(final Set<E> set1, final Set<?> set2);  }
@Test public void testLengthOfCollection() { String[] input = new String[] {"zer", "one", "two", "three", "four"}; assertEquals("invalid array size", input.length, CollectionUtils.getLengthOfCollection(input)); }