title: Java: for loop crashing using string charAt method
body: <p>I have a bug in this block of code. The debugger suggest it´s cause is this line of code <code>char chr = getSecretWord.charAt(i);</code>     </p>
  
  <p>What this code does is look for a match between <code>userInput</code> and <code>secretWord</code>. I have the <code>for loop</code> to go through the length of the secretWord letters one by one, and if there is a letter matching  return true. If not, return false... but the program crashes when it is suppose to just return false... I guess it is something with this line, but do not know exactly what <code>getSecretWord.charAt(i);</code></p>
  
  <pre><code>    private boolean isMatchingSecretWord(String userInput)
  {
      String secretWord = "";
      String getSecretWord = getSecretWord();
      for (int i = 0; i &lt;= getSecretWord.length();i++)
          {
          char chr = getSecretWord.charAt(i);
          secretWord = ""+chr;
  
          if (secretWord.equals(userInput))
          {
              println("is true");
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>As an side note, is what I´ve done with this code correct, assigning the getSecretWorld() Method to a String so I can use the Strings method <code>length()</code>? </p>
  
  <p><code>String getSecretWord = getSecretWord();</code></p>
  
  <p><code>for (int i = 0; i &lt;= getSecretWord.length();i++)</code></p>
  
  <p><strong>Debug code:</strong></p>
  
  <pre><code>Exception in thread "Thread-4" java.lang.StringIndexOutOfBoundsException: String index out of range: 4    
      at java.lang.String.charAt(String.java:686)    
      at Hangman.isMatchingSecretWord(Hangman.java:49)    
      at Hangman.userInput(Hangman.java:34)    
      at Hangman.run(Hangman.java:20)*
  </code></pre>