Multidimensional arrays and arrays of arrays



Hello
How can I distinguish if an array is multidimensional of if it just
contains an array? Or put it another way how can I tell at runtime
whether a/b in the example below is an array containing an array, or
if it is a multidimensional array.
If I know beforehand exactly which type it is, I can use instanceof
(see example), but I don't (especially the number of dimensions, I
don't know).
Else I can call getClass().getName() on the object and see if it
starts with "[[" (pretty ugly IMHO).
Is there another, cleaner method to do this?

public static void main(String[] args) {
Object[] a = new Object[1];
a[0] = new float[12];

Object b = new float[1][12];

if(a instanceof float[][]){
System.out.println("a is float[][]");
}
if(b instanceof float[][]){
System.out.println("b is float[][]");
}
}

prints "b is float[][]" (but not for a) as expected.

Phil
.



Relevant Pages

  • Array Operators (Was help executing a list)
    ... Thanks to all who helped with my attempt at producing array numerical operators for lisp. ... ;; Calls function f for the ith element in the arrays in args ... (defun f-one-element (f i args) ... (defun array-1f (f a) ...
    (comp.lang.lisp)
  • Re: Help-a-Dummy Please
    ... stack around Switches is corrupt". ... As the memory for the array char * Args[] is allocated outside the object as ...
    (microsoft.public.vc.language)
  • Re: argument parser throws error if 0-length $args used...
    ... Hmmm...that's a good point in general, but I would still think the metadata ... positional parameter to bind $args to; it's whether $args should be passed ... array, I would think that the metadata telling you that $args *would* be an ... be any unexpected flattening or expansion going on -- I wanted to see the ...
    (microsoft.public.windows.server.scripting)
  • Re: Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show excepti
    ... @Args means that the pointer to Args is passed as the paranmeter. ... Pass all parameters in one string: ... I haven't got a clue what "array of const" is. ... CallStaticVoidMethod, but the compiler errored "Incompatible Types ...
    (comp.lang.java.programmer)
  • Re: Passing Unknown Number of Varaibles
    ... orange's signature is: public Int orange ... Are you really trying to pass a variable number of arguments to a method that takes an array? ... public static void main(Stringargs) { ...
    (comp.lang.java.help)