Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static Class<?> getTypeOfFirstElement(Collection<?> collection) { if (collection.isEmpty()) { return null; } else { return getFirstObject(collection).getClass(); } } public static Object getFirstObject(Collection<?> collection) { Iterator<?> iterator = collection.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } } }