title: Java, check is substring of string doesn't "exist"
body: <p>I have a while loop that is supposed to seperate a word into individual letters... It works but then when ever i try to check if a substring that does not exist is null it throws exceptions...</p>
  
  <pre><code>    private static void seperateWord(String word) {
      boolean running = true;
      int count = 0;
      while (running) {
          if (word.substring(count, count + 1).equals("null")) {
              running = false;
              return;
          } else {
              letter[count] = word.substring(count, count + 1);
              System.out.println(letter[count]);
              count++;
          }
      }
  }
  </code></pre>
  
  <p>It does output all the letters correctly until it gets to the end of the string and has nothing left to read... as in it just does not exist. It throws this exception...</p>
  
  <pre><code>    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4
  at java.lang.String.substring(Unknown Source)
  at Class.seperateWord(Class.java:33)
  at Class.main(Class.java:13)
  </code></pre>
  
  <p>Line 33 is :: if (input.substring(count, count + 1).equals("null")) {</p>
  
  <p>Line 13 is just where I call the method.</p>
  
  <p>The text I entered is "abc"</p>
  
  <p>Thanks in advance for any help!</p>