Java external: how to check for equality between Atom [] elements
I am new to both java and java externals for MAX.
What I want to do is having two lists of Atoms, one in each inlet and then perform some actions on them. For the time being I want to check whether for example myArray_1[x] == myArray_2[y]. To experiment I send two identical lists in the inlets. But here is what I don’t understand: Suppose that I have two Atom arrays:
myArray_1 = {56, 23, 5, blah} and myArray_2 = {56, 23, 5, blah} .
Now here are some results:
outlet(0, myArray_1[0]) // it correctly outputs 56
outlet(1, myArray_2[0]) // it correctly outputs 56, again
Also:
myArray_1[0].isInt() // it correctly confirms that this is true by posting a relevant message
myArray_2[0].isInt() // it correctly confirms that this is also true by posting the same message
But:
When I check whether myArray_1[0] == myArray_2[0] it returns false although both have the same value (56) and both are recognized as integers.
Doesn’t the ‘equals’ (==) operator work here, and why? Should I use another comparing method instead, and which one?
What am I missing?
Thanks in advance
== , when not used on primitive values(e.g. 5 == 5), checks whether two objects are the exact same object.
.equals() checks for equality of the value of the objects, and should work in your case:
myArray_1[0].equals(myArray_2[0]) will test for equality of the values of those two objects.
Hope this helps
Yes, it helps. I was searching for such a method and just saw it.
Thank you.