We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using arduino with processing. I'm sending a 10 character string from arduino to processing, using Serial.prinln(); I receive the same string in processing without any problem. But when I compare the same string inside the Serial Event function in processing, it doesn't match. I don't understand the reason. I tried different reading methods. nothing work. Then i read the serial port using a byte character array and converted it to string and then compared it. doesn't work. I need to used these serial read strings to load a picture to the window and display. Please help.
Answers
This question been asked and answered many times, it is also in both the wiki and the reference:
http://wiki.processing.org/w/Strings_and_Equality
http://processing.org/reference/String_equals_.html
Next time please:
In Java, when the equality operator
==
is used to compare objects, that is,anything which isn't any of the 8 primitive types, what is actually compared is their memory addresses!
A String is an object, hence it resides in a contiguous block of memory from some unique memory address.
That's why the equals() method exists, in order to compare the object contents rather their references!
Generally, other programming languages can be less rigid.
And their
==
operator work as we think they should! ;)