Get array dimensions


import java.lang.reflect.Array;

public class Main {
  public static void main(String[] argv) throws Exception {
    Object o = new int[1][2][3];
    int len = Array.getLength(o); // 1
    System.out.println(len);
    int dim = getDim(o); // 3
    System.out.println(dim);
  }

  public static int getDim(Object array) {
    int dim = 0;
    Class cls = array.getClass();
    while (cls.isArray()) {
      dim++;
      cls = cls.getComponentType();
    }
    return dim;
  }
}
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