Need Help-Sonal

i created two dimensional array. I need to initialize these array only one time or if i change passing values to constructor. i don't want to reinitialize when i run it again(second time) because second time i just want to update this.

[int arraySize=numofPage;

//need to fill array only one time second time i just want to update but //don't know how.

int PageArray[][]=newint[arraySize][1];

for(int i=0;i<numofPage;i++)

{

PageArray [i] [1]=0;//as invalid

System.out.println("PageArray initialization"+PageArray[i][j]);

}

/code]

[code]

Thanks.>

[973 byte] By [sonalgupta79a] at [2007-11-27 2:33:02]
# 1

> i created two dimensional array. I need to initialize

> these array only one time or if i change passing

> values to constructor. i don't want to reinitialize

> when i run it again(second time) because second time

> i just want to update this.

>

> [int arraySize=numofPage;

> //need to fill array only one time second

> time i just want to update but //don't know how.

> int PageArray[][]=new int[arraySize][1];

>

> for(int i=0;i<numofPage;i++)

> {

>PageArray [i] [1]=0; //as invalid

> System.out.println("PageArray

> initialization"+PageArray[i][j]);

>

> de]

> [code]

> Thanks.

First of all, why you need a two dimensional array [n][1] ? it's a one-dimensional array, not?

Secondly, you don't need to initalize it to "0" because when you create a new int array immediately it's initialized at it's default values wich are 0.

PageArray is a class atribute? you have to explain better what's the PageArray value and why do you need it, as what do you mean with "run it second time" because "second time" you run a program PageArray must be reinitalized or loaded from a file instead...

Otherwise, if you're talking about "running" the loop.. you can avoid the initialization by doing

if (PageArray!=null) {...}

alexpallarsa at 2007-7-12 2:49:16 > top of Java-index,Java Essentials,Java Programming...