If an object is an array, how do I find out its type?
Created May 4, 2012
John Zukowski Use the getComponentType() method of the class of the object that is the array.
public class ArrayReflection { public static void main (String args[]) { printType(args); } private static void printType (Object object) { Class type = object.getClass(); if (type.isArray()) { Class elementType = type.getComponentType(); System.out.println("Array of: " + elementType); } } }