-3

how do i do: char[][][] map = new char[y][z][x]; but define the size with:

int[] size = new {y,z,x};

I tried looking it up but i couldn't find anything helpful.

  • 1
    https://stackoverflow.com/questions/1200621/how-do-i-declare-and-initialize-an-array-in-java – OldProgrammer May 16 '23 at 16:20
  • If this is not a duplicate, please [edit] your question to include a [mre] that shows your revised approach. – trashgod May 16 '23 at 16:34
  • Your title says int array but your example uses a char array. And what are all the dimensions for x,y,and z? – WJS May 16 '23 at 16:36
  • 1
    `int x = size[2]; int y = size[0]; int z = size[1]; char[][][] map = new char[y][z][x];` – user16320675 May 16 '23 at 16:44
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 18 '23 at 00:27

1 Answers1

0

If I understand the question correctly, you're looking to initialize the array with a set of values.
As opposed to initializing an array with a fixed length, and then adding the values one at a time.

Your code is correct, just remove the new keyword.

int[] size = { y, z, x };
Reilas
  • 3,297
  • 2
  • 4
  • 17