// can arrays have zero length in any dimension? // (inspired by a student's question -- thanks Stella) public class array_zero { public static void main(String[] args) { int[] a = new int[0]; // this compiles and runs System.out.println(a.length); // yes, the size is zero // but this is kind of pointless...why? // System.out.println(a[0]); // won't work int[][] b = new int[0][]; // yes, this compiles and runs // this is even more pointless, since you can't access // the first index of b int[] c = new int[] {}; // works for anon arrays, too System.out.println(c.length); // yes, the size is zero // so, a thought exercise...what kind of situation might you need // a zero-length array? (Hint: think of situations requiring // ragged arrays) } } /* output: 0 0 */