Get array upperboundTag(s): Language
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); } }
public class ArrayDim { public static void main(String args[]) { String[][] data = new String[3][4]; System.out.println("This array has " + ArrayDim.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 ); } }
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com