joey rohan
joey rohan

Reputation: 3566

Array initialization

I have a 3-D array [8][8][1002], which remains static with every run(values don't change). Each page of array contains binary combination (8x8 matrix).

The array will take a lot of time to load, which I want to avoid.

Any way to reduce the time taken?

Or any other data structure may work effectively faster?

UPDATE:

The initialization of array is done by exhaustive method :

Loop1 for i:
  Loop2 for j:
   Loop3 for k:
   array[i][j][k]=1 //or 0 some logic

By loading, I mean array initialization.

Upvotes: 0

Views: 150

Answers (2)

Andres
Andres

Reputation: 10727

If speed is a must, try declaring the array as final, and initialize it while you create it. That'll take a lot of code but will probably be faster.

final int[][][] array = {...}

Upvotes: 0

Ashot Karakhanyan
Ashot Karakhanyan

Reputation: 2830

If you want to initialize with 0, so you don't need to write any init code, before default value is 0 when you creating an instance of array:

final int[][][] array = new int[1][1][1];
System.out.println(array[0][0][0]);

The result is: 0

Upvotes: 1

Related Questions