title: Java String index out of range error
body: <p>I'm running into some issues with some java code that I do not know how to fix. I was wondering if I could get some help with figuring out why I keep getting</p>
  
  <pre><code>java.lang.StringIndexOutOfBoundsException: String index out of range: 1
  </code></pre>
  
  <p>Here's the code snippet where the problem is popping up (its part of a larger package for an assignment..)  :</p>
  
  <pre><code>public class MyMapper extends Mapper {
  
  @Override
  //method takes docName and data as string
  public void map(String documentID, String document) {
  
      //this string array hold all the delimiters for our split
      //String[] separators = {",", ".", "!", "?", ";", ":", "-", "' "," "};
  
      //splits the string 'document' according to delimiters
      String[] words = document.split(",|\\.|\\!|\\?|\\;|\\:|\\-|\\' |\\ |\\'.");
  
  
      // for each word in String[] words, check that each word is legitimate
      for (String word : words) {
  
          if (isAlpha(word)){
              //System.out.println(word);
              emit(word.substring(0, 1).toUpperCase() , "1");
          }
  
          else;
  
      }
  }
  
  
  // private helper method to check that each word is legitimate (alphas-only)
  private boolean isAlpha(String name) {
  char[] chars = name.toCharArray();
  
  for (char c : chars) {
      if(!Character.isLetter(c)) {
          return false;
      }
  }
  
  return true;
  }
  
  }
  </code></pre>
  
  <p>What I am trying to do is take in a document (stored in string form through bufferedReader) and seize the first letter of each word in the doc, and capitalize them.</p>
  
  <p>***** Updated Code***** </p>
  
  <p>I decided to go with the suggested check for the empty "word" in my private helper method.  Everything works now. </p>
  
  <p>Here is the updated code for documentation purposes:</p>
  
  <pre><code>// private helper method to check that each word is legitimate (alphas-only)
  private boolean isAlpha(String name) {
  
  if (name.equals("")) 
      return false;
  
  char[] chars = name.toCharArray();
  
  for (char c : chars) {
      if(!Character.isLetter(c)) {
          return false;
      }
  }
  
  return true;
  </code></pre>