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 › Array assignment
Page Index Toggle Pages: 1
Array assignment? (Read 654 times)
Array assignment?
Jun 2nd, 2006, 9:29pm
 
Quick example to illustrate question:

float[] a= new float[width*height];
float[] b= new float[width*height];

// Fill a with values

b=a;                // What does this do?  
arraycopy(a,b);     // Compared to this.

-----------------------------------------



Re: Array assignment?
Reply #1 - Jun 2nd, 2006, 10:49pm
 
Run this, it should help illustrate the difference:

float[]a = {1,2,3};
float[]b = {4,5,6};

float[]c = {1,2,3};
float[]d = {4,5,6};

b=a;
println(a);
println(b);
println(a==b);
b[1]=10;
println(a);

println();

arraycopy(c,d);
println(c);
println(d);
println(c==d);
d[1]=10;
println(c);
Re: Array assignment?
Reply #2 - Jun 5th, 2006, 11:39pm
 
OK so using the = operator on arrays changes what they point
to.  I didn't see anything about that in the docs, but I guess you can do pointer stuff that way.  Thanks.
Re: Array assignment?
Reply #3 - Jun 6th, 2006, 4:47am
 
yup. In java arrays, classes and interfaces are reference types.
Page Index Toggle Pages: 1