Loading...
Logo
Processing Forum

very frustrating problem with IF statement

Answered
  • Need more info
  • Answered
  • Working on it
in Programming Questions  •  3 years ago  
Howdy all;

I'm encountering a very frustrating problem with the below IF statement:

Copy code
  1.     String test = placemark.getChild(3).getName();
  2.     if (test == "Polygon") {
  3.       XMLElement polygon = placemark.getChild(3);
  4.       XMLElement outerBound = polygon.getChild(0);

For some reason, test == "Polygon" will NOT return true. I've verified that the output from the getName() method is indeed a String, and that it is "Polygon" with identical capitalization and no leading or trailing spaces. Does anyone have any ideas what else could be the problem?

Many thanks,

Josh

   

Replies(2)

String is a class not a simple type, so you must use equals() to compare.

if (test.equals("Polygon")) {...}

see http://processing.org/reference/String.html
That does it! Many thanks for your help.

Josh