Get array(component) type


import java.awt.Button;

public class SampleComponentReflection {

  public static void main(String[] args) {
    int[] ints = new int[2];
    Button[] buttons = new Button[6];
    String[][] twoDim = new String[4][5];

    printComponentType(ints);
    printComponentType(buttons);
    printComponentType(twoDim);
  }

  static void printComponentType(Object array) {
    Class arrayClass = array.getClass();
    String arrayName = arrayClass.getName();
    Class componentClass = arrayClass.getComponentType();
    String componentName = componentClass.getName();
    System.out.println("Array: " + arrayName + ", Component: "
        + componentName);
  }
}
Home 
  Java Book 
    Runnable examples  

Reflection Array:
  1. Create an array of 10 ints.
  2. Create a 10x20 2-dimensional int array
  3. Fill and display an array
  4. Get and Set the Value of an Element in an Array Object
  5. Get array(component) type
  6. Get array dimensions
  7. Get array length
  8. Get array name and type
  9. Is an Object an Array