title: java if statement not breaking the "for loop"
body: <p>I am newbie in java but I think I have done well teaching myself in these few weeks. But now I am stuck at this loop.</p>
  
  <p>Here is a method from one of my class. To help me debug, I have added "myString" string and "syntax" list inside this method to demonstrate what is happening and to keep it simple, at least for now.</p>
  
  <pre><code>public void getIndex(){
      String myString = "2 2 + 3 5";
      String[] syntax = myString.split(" ");
  
      for (int index = 0; index &lt; syntax.length; index++){
          System.out.println("current index is: " + index);
          System.out.println("It has: " + syntax[index]);
          // these print statements are made to help me debug
          if (syntax[index] == "+"){
              indexNeeded = index;
              break;
          }
      }
      System.out.println("Index Needed: " + indexNeeded);   
  </code></pre>
  
  <p>As you can see inside the loop, I want to break the "for loop" when the element of the list, "syntax" is "+".
  (I am showing "+" here but it can be anything in the actual program.)</p>
  
  <p>Here is the output, when run this method:</p>
  
  <pre><code>current index is: 0
  It has: 2
  current index is: 1
  It has: 2
  current index is: 2
  It has: +
  current index is: 3
  It has: 3
  current index is: 4
  It has: 5
  Index Needed: 0
  </code></pre>
  
  <p><strong>The loop should have stopped when it found "+" but it seems that "if statement" is not working at all, and hence "indexNeeded" hasn't changed.</strong></p>
  
  <p>It's a simple method but what am I doing wrong here?</p>