| Real'sHowTo |
|
|
Custom Search
|
| Real'sHowTo |
|
|
Custom Search
|
class ArrayLength {
public static void main(String args[]) {
String[][] data = new String[3][4];
System.out.println("Dimension 1: " + data.length);
System.out.println("Dimension 2: " + data[0].length);
}
}class ArrayDim {
public static void main(String args[]) {
String[][] data = new String[3][4];
System.out.println("This array has " + getDim(data) + " dimensions");
// expected output :
// "This array has 2 dimensions"
}
public static int getDim(Object array ) {
int dim=0;
Class c = array.getClass();
while( c.isArray() ) {
c = c.getComponentType();
dim++;
}
return( dim );
}
}Written and compiled by Réal Gagnon ©1998-2013
[ home ]