Multidimensional arrays and arrays of arrays
- From: Philipp <djbulu@xxxxxxxxx>
- Date: Thu, 15 Jan 2009 03:49:49 -0800 (PST)
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
.
- Follow-Ups:
- Re: Multidimensional arrays and arrays of arrays
- From: Daniel Pitts
- Re: Multidimensional arrays and arrays of arrays
- From: Patricia Shanahan
- Re: Multidimensional arrays and arrays of arrays
- From: RedGrittyBrick
- Re: Multidimensional arrays and arrays of arrays
- From: Joshua Cranmer
- Re: Multidimensional arrays and arrays of arrays
- Prev by Date: Re: problem in file upload
- Next by Date: Re: Multidimensional arrays and arrays of arrays
- Previous by thread: www.honestaaa.com wholesal nike jordan adidas prada gucci bape shoes ugg boot
- Next by thread: Re: Multidimensional arrays and arrays of arrays
- Index(es):
Relevant Pages
|