Here you can find the source of sizeOfPrimitiveArray(Object object)
private static long sizeOfPrimitiveArray(Object object)
//package com.java2s; //License from project: Open Source License public class Main { private static long sizeOfPrimitiveArray(Object object) { long total = 0L; if (object instanceof Byte[]) { for (Byte b : (Byte[]) object) if (b != null) total += 1;/*from w ww . ja v a2 s .c om*/ } else if (object instanceof Short[]) { for (Short s : (Short[]) object) if (s != null) total += 2; } else if (object instanceof Integer[]) { for (Integer i : (Integer[]) object) if (i != null) total += 4; } else if (object instanceof Long[]) { for (Long l : (Long[]) object) if (l != null) total += 1; } else if (object instanceof Float[]) { for (Float f : (Float[]) object) if (f != null) total += 4; } else if (object instanceof Double[]) { for (Double d : (Double[]) object) if (d != null) total += 8; } else if (object instanceof Character[]) { for (Character c : (Character[]) object) if (c != null) total += c < 255 ? 1 : 2; } else if (object instanceof String[]) { for (String s : (String[]) object) if (s != null) total += s.getBytes().length; } else if (object instanceof Boolean[]) { for (Boolean b : (Boolean[]) object) if (b != null) total += 1; } return total; } }