title: Getting java.lang.ArrayIndexOutOfBoundsException, looked, cannot find an example thats the same
body: <p>I am writing a "tweet checker" code for my AP Computer Science Class. The code is supposed to check that the length of the tweet is within the 140 character limit and, if so, prints the amount of hashtags, @, and links used. I am using the .split method to put all the characters into an array, and then I am accessing the array with for loops to find the specific characters. </p>
  
  <p>I keep encountering a java.lang.ArrayIndexOutOfBoundsException, which I know means that I am trying to access a nonexistent element in my string, such as element 46 for an array of 46 characters, but I do not know what the exact problem is here. I got harped on last time for not "looking hard enough" but I have searched for over 2 hours on only this subject, and I am simply a high school student.</p>
  
  <p>I appreciate all the help.</p>
  
  <pre><code>import java.util.Scanner;
  import java.lang.Math; 
  
  class Main{
      public static void main(String[] args)
       {
        Scanner scan = new Scanner (System.in);
        System.out.println("Please enter a tweet:");
        String tweet = scan.nextLine();
        int length = tweet.length ();
        String[] tweetArray = tweet.split ("");
        int c = 0;
        int d = 0;
        int e = 0;
        int i = 0;
        if (length &gt; 140)
          System.out.println("Excess Characters: " + (length - 140));
        else
        {
          System.out.println("Length Correct");
          for (i = 0; i &lt; length; i++)
          {
            if (tweetArray[i].equals("#"))
            {
              if(!tweetArray[i+1].equals(" "))
              {
                c++;
              }
            }
          }
          System.out.println("Number of Hastags: " + c);
          for (i = 0; i &lt; length; i++)
          {
            if (tweetArray[i].equals("@"))
            {
              if(!tweetArray[i+1].equals(" "))
              {
                d++;
              }
            }
          }
            System.out.println("Number of Attributions: " + d);
            for (i = 0; i &lt; length; i++)
            {
              if((tweetArray[i].equals("h")) || (tweetArray[i].equals("H")))
              {
                if(tweetArray[i+1].equals("t") || tweetArray[i+1].equals("T"))
                {
                  if(tweetArray[i+2].equals("t") || tweetArray[i+2].equals("T"))
                  {
                    if(tweetArray[i+3].equals("p") || tweetArray[i+3].equals("P"))
                    {
                      if(tweetArray[i+4].equals(":"))
                      {
                        if(tweetArray[i+5].equals("/"))
                        {
                          if(tweetArray[i+6].equals("/"))
                          {
                            if(!tweetArray[i+7].equals(" "))
                            {
                              e++;
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          System.out.println("Number of Links: " + e);
        }
  
  
  
  
  }
  }
  </code></pre>