// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class GetDim {
    public static List<Integer> getDim(Object obj) {
        List<Integer> res = new ArrayList<>();
        Object currobj = obj;
        Class<?> clz = obj.getClass();
        while(clz != null) {
            if(clz.isArray()) {
                res.add(Array.getLength(currobj));
                currobj = Array.get(currobj,  0);
            }
            clz = clz.getComponentType();
        }
        return res;
    }
    public static void test(Object o) {
        System.out.println(getDim(o));
    }
    public static void main(String[] args) {
        test(123);
        test("ABC");
        test(new int[2]);
        test(new int[2][3]);
        test(new int[2][3][4]);
    }
}
