Determining the component type of an array

Very simple – first obtain the Class object representing the type of the array itself:

  Integer [] arr = new Integer[5];
  Class arrType = arr.getClass();

And then obtain its type using the Class.getComponentType() method:

  Class componentType = arrType.getComponentType();
  System.out.println(componentType.getName());

The above code should print “java.lang.Integer”.