+ 1

Is it possible to creates muti dimensional array based on input value?

Is it possible to create multi dimensional array based on input value. For example int input = 3 // this input represents dimensional length Int dimen[3][3][3]; // based on input value i need to create variable 3 dimensional array with the length of 3 (based on input value) each . I don't want to use collection's api

20th Sep 2020, 7:04 PM
Naveen Surya
Naveen Surya - avatar
4 ответов
+ 2
I don't think that's possible.
20th Sep 2020, 7:18 PM
Avinesh
Avinesh - avatar
+ 1
You can definitely define the length of the array in that way but applying the same for the dimension is not possible. You are trying to say that if I give 3. The JVM should make a 3 dimension array ready?
20th Sep 2020, 7:12 PM
Avinesh
Avinesh - avatar
+ 1
Yes
20th Sep 2020, 7:13 PM
Naveen Surya
Naveen Surya - avatar
0
// use array in array like Object[] a0 = new Object[3]; Object[] a1 = new Object[3]; Object[] a2 = new Object[3]; int[] ia3 = {100,1,2,3}; a2[0] = ia3; a1[0] = a2; a0[0] = a1; Object[] a = (Object[]) a0[0]; //a1 a = (Object[]) a[0]; //a2 int[] ia = (int[]) a[0]; //ia3 System.out.println(ia[0]);
21st Sep 2020, 9:33 PM
zemiak