title: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
body: <p>I keep getting </p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
  at java.util.ArrayList.rangeCheck(Unknown Source)
  at java.util.ArrayList.get(Unknown Source)
  at hartman.ShortestString.printShortestString(ShortestString.java:40)
  at hartman.ShortestString.main(ShortestString.java:28)
  </code></pre>
  
  <p>How do i fix this?</p>
  
  <pre><code>package hartman;
  
  import java.util.ArrayList;
  import java.util.Scanner;
  
  public class ShortestString {
  
      public static void main(String[] args) {
          System.out.printf("WELCOME TO SHORTEST STRING\n\n");
          System.out.printf("Type \".\" when done entering data.\n\n");
  
          ArrayList&lt;String&gt; myArray = new ArrayList&lt;&gt;();
          Scanner keyboard = new Scanner(System.in);
          boolean keepAsking = true;
  
          while (keepAsking) {
              System.out.printf("Enter string: ");
              String userInput = keyboard.nextLine();
  
              if (userInput.equals(".")) {
                  keepAsking = false;
              } else {
                  myArray.add(userInput);
              }
          }
  
          printShortestString(myArray);
          System.out.printf("\n\nGOODBYE!\n");
          keyboard.close();
      }
  
      public static void printShortestString(ArrayList&lt;String&gt; myArray) {
  
          int index;
          int index1 = 1;
  
          for (index = 0; index &lt; myArray.get(index).length(); index++) {
              if (myArray.get(index).length() &lt; myArray.get(index1).length()) {
                  System.out.printf("\nShortest string is \"%s\" with length %d",
                          myArray.get(index), myArray.get(index).length());
              } else {
                  index1++;
              }
          }
          return;
      }
  }
  </code></pre>