Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {
    public static void main(String[] args) {
        int[][][] intArray = new int[1][2][3];

        System.out.println("int[][][] dimension is " + getArrayDimension(intArray));
    }

    public static int getArrayDimension(Object array) {
        int dimension = 0;
        Class c = array.getClass();
        if (!c.isArray()) {
            throw new IllegalArgumentException("Object is not  an  array");
        }
        while (c.isArray()) {
            dimension++;
            c = c.getComponentType();
        }
        return dimension;
    }
}