Here you can find the source of findCommonElementType(Collection> collection)
public static Class<?> findCommonElementType(Collection<?> collection)
//package com.java2s; import java.util.Collection; public class Main { public static Class<?> findCommonElementType(Collection<?> collection) { if (isEmpty(collection)) { return null; }//from ww w. j ava 2 s .c om Class<?> candidate = null; for (Object val : collection) { if (val != null) { if (candidate == null) { candidate = val.getClass(); } else if (candidate != val.getClass()) { return null; } } } return candidate; } public static boolean isEmpty(Collection<?> collection) { return (collection == null || collection.isEmpty()); } }