Here you can find the source of findCommonElementType(Collection collection)
public static Class<?> findCommonElementType(Collection collection)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; import java.util.Map; public class Main { public static Class<?> findCommonElementType(Collection collection) { if (isEmpty(collection)) { return null; } else {/* w ww.j a v a2s.c o m*/ Class candidate = null; Iterator i$ = collection.iterator(); while (i$.hasNext()) { Object val = i$.next(); 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(); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } }