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.
Page Index Toggle Pages: 1
array equality (Read 269 times)
array equality
Dec 2nd, 2008, 10:09pm
 
I have a quick question. I apologize in advance if this has already been addressed. I'm using 152.

The following doesn't print anything. Why?

Quote:
float[]one = {1.1, 2.2, 3.3};
float[]two = new float[3];

arrayCopy(one, two);

if(one == two || one.equals(two)) {
  println("yes");
}

float[]three = new float[6];
float[]four = new float[6];

getMatrix().get(three);
getMatrix().get(four);

if(three == four || three.equals(four)) {
  println("yes2");
}

Re: array equality
Reply #1 - Dec 3rd, 2008, 9:41am
 
try 'Arrays.equals(one, two)' to compare the content of arrays.

Equality for Java arrays is a little different from what you would expect Smiley
Re: array equality
Reply #2 - Dec 3rd, 2008, 10:52pm
 
Thank you. Is this kind of comparison uncommon? I thought it might be better documented in the Processing reference.
Re: array equality
Reply #3 - Dec 3rd, 2008, 11:25pm
 
I never had to do an array comparison so far...
Page Index Toggle Pages: 1