title: Setting a variable to a value in if statement
body: <pre><code>static int findPerson(String n, int NP, Friend[] giftGivers){
  
      int index = 0;
  
      for (int i = 0; i &lt; NP; i++){
      if (giftGivers[i].name == n){
              index = i;
      }
      }
  
      return index;
  }
  </code></pre>
  
  <p>I have this code in Java for a method to search through an array of Friends to find the index number of the person with the name input by String n. however i have found that the index number does not set to the index number it is should be. Is it because it is in the if statement?</p>