title: Java Arraylist got java.lang.IndexOutOfBoundsException?
body: <p>I'm a general 3D artist, switched from my career and started to learn programming.
  I've got a problem with c106a handout #5.</p>
  
  <p>The code works, but I've still got some error log here.</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
  at java.util.ArrayList.RangeCheck(ArrayList.java:547)
  at java.util.ArrayList.get(ArrayList.java:322)
  at UniqueNames.showUnique(UniqueNames.java:23)
  at UniqueNames.main(UniqueNames.java:39)
  </code></pre>
  
  <p>Why does <code>Arraylist</code>, which can stretch its capacity on its own, still get an <code>OutOfBoundsException</code>?</p>
  
  <p>Here's my full code:</p>
  
  <pre><code>import acm.io.*;
  import acm.program.ConsoleProgram;
  import acm.util.*;
  import java.io.*;
  import java.util.ArrayList;
  import java.lang.*;
  
  public class UniqueNames extends ConsoleProgram{
  
    static ArrayList&lt;String&gt; meString = new ArrayList&lt;String&gt;();
    static String input ;
  
      public static void storeUnique(String input){
          if (!meString.contains(input))
             {
              meString.add(input);
              }
      }
  
      public static void showUnique(ArrayList&lt;String&gt; meString){
          System.out.println("Unique name list contains:");
          for(int i=0 ;i&lt;= meString.size() ;i++){
              System.out.println(meString.get(i));
            }
        }
  
      public static void main(String[] args){
  
               try{
                  InputStreamReader stream = new InputStreamReader(System.in);
                  BufferedReader br = new BufferedReader(stream);
                     while (true){
                         System.out.println("Enter name:");
                         String input = br.readLine();
                         if (input.equals("")) break;
                         storeUnique(input);
                        }  
  
                    {showUnique(meString);}  
                  }
               catch(IOException e){
                  }
      }
  }
  </code></pre>