If an object is an array, how do I find out its type?

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[]) {
  private static void printType (Object object) {
    Class type = object.getClass();
    if (type.isArray()) {
      Class elementType = type.getComponentType();
      System.out.println("Array of: " + elementType);