Version 2 of A Java class for calculating size of iterable/array
import java.util.Collection;
/**
* Created by IDEA on 16/11/14.
*/
public class Size {
public static int size(Iterable<?> data) {
if (data instanceof Collection) {
return ((Collection<?>) data).size();
}
int counter = 0;
for (Object i : data) {
counter++;
}
return counter;
}
public static int size(int[] data) {
return data.length;
}
public static int size(double[] data) {
return data.length;
}
public static int size(float[] data) {
return data.length;
}
public static int size(short[] data) {
return data.length;
}
public static int size(boolean[] data) {
return data.length;
}
public static int size(char[] data) {
return data.length;
}
public static <T> int size(T[] data) {
return data.length;
}
}