Java tutorial
//package com.java2s; import android.support.annotation.NonNull; import android.text.TextUtils; import java.lang.reflect.ParameterizedType; import java.util.Collection; import java.util.List; public class Main { @NonNull public static Class getListTypeClass(List<?> list) { Class elementType; if (isEmpty(list)) { final Class<? extends List> listClass = list.getClass(); final ParameterizedType genericSuperclass = (ParameterizedType) listClass.getGenericSuperclass(); elementType = (Class) genericSuperclass.getActualTypeArguments()[0]; } else { elementType = list.get(0).getClass(); } return elementType; } public static <T> boolean isEmpty(T[] array) { return array == null || array.length == 0; } public static boolean isEmpty(int[] array) { return array == null || array.length == 0; } public static boolean isEmpty(long[] array) { return array == null || array.length == 0; } public static boolean isEmpty(Collection collection) { return collection == null || collection.isEmpty(); } public static boolean isEmpty(String string) { return TextUtils.isEmpty(string); } public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; } }