We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Delete a global array
Page Index Toggle Pages: 1
Delete a global array (Read 506 times)
Delete a global array
Sep 29th, 2007, 7:03pm
 
I have a global array that I want use once and then re-populate with new values (making it an array of new values with the old name). How can I do that?

I create the original array like this:

int[] rawSeq = new int[0];

but running that same code at the point I want to recreate the array doesn't work. The old values remain and the new values are added to the end of the array.

Thanks.
Re: Delete a global array
Reply #1 - Sep 30th, 2007, 2:17am
 
It all depends how you're populating the array.

Usually you'd do something like this:

Code:

int[] rawSeq = new int[rawSeqLength];

for (int i=0; i<rawSeqLength; i++){
rawSeq[i] = getNumber(i);
}

//now re-initialize the array

rawSeq = new int[newRawSeqLength];

for (int i=0; i<newRawSeqLength]; i++){
rawSeq[i] = getNewNumber(i);
}



It sounds like you're using a method that adds on to the end of the array.  In that case, just writing

rawSeq = new int[0];

should do the trick for you (note no int[] declaration is needed, as the rawSeq array variable is already declared).

If not, maybe try to post the code so we can see what's going on.
Re: Delete a global array
Reply #2 - Oct 1st, 2007, 12:12pm
 
The first solution -  rawSeq = new int[newRawSeqLength] - worked great. Thanks.
Page Index Toggle Pages: 1