Issues finding strings

Hi!
I have some issues with the split() command and == “xyz”. I am currently creating a console like program, in which you can type “draw ellipse x y r1 r2”. However whenever I use String segments[] = split(command,' '); it prints that the segments[0] = "draw" however when I use if(segments[0] == "draw" {} it says it is not the same.

String com = "draw circle";

void setup() {
  
}

void draw() {
  
}

void mousePressed() {
  execute(com);
}

void execute(String command) {
  String segments[] = split(command," ");
  //println(segments[0],"draw");
  //String comNew = "";
  //for(int i = 0; i < segments[0].length(); i++) {
  //  comNew += segments[0].charAt(i);
  //}
  
  if(segments[0] == "draw") {
    println("aaaaaaaaaaaaaa");
  }
}

In Java Strings, the == operator is used to check a match of the reference of both the string instances whereas equals() method used to check if the content of the strings match.

  if (segments[0].equals("draw")) println("I found draw");
  else println("I did not find draw");
1 Like