title: Remove last element of a list
body: <p>I've been tasked to do the below in a newbie Java tutorial on ArrayList</p>
  
  <pre><code>// 1) Declare am ArrayList of strings
      // 2) Call the add method and add 10 random strings
      // 3) Iterate through all the elements in the ArrayList
      // 4) Remove the first and last element of the ArrayList
      // 5) Iterate through all the elements in the ArrayList, again.
  </code></pre>
  
  <p>Below is my code</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Random;
  
  public class Ex1_BasicArrayList {
  
      public static void main(String[] args) {
          ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
          for (int i = 0; i &lt;= 10; i++){
              Random rand = new Random();
              String randy = String.valueOf(rand);
              list.add(randy );
          }
          for (int i = 0; i &lt; list.size(); i++){
              System.out.print(list.get(i));
          }   
          list.remove(0);
          list.remove(list.size());
  
          for (int i = 0; i &lt; list.size(); i++){
              System.out.print(list.get(i));
          }
      }
  }
  </code></pre>
  
  <p>The code runs, but I get the below error message when it runs. Any ideas on what I'm doing wrong?</p>
  
  <pre><code>java.util.Random@7852e922java.util.Random@4e25154fjava.util.Random@70dea4ejava.util.Random@5c647e05java.util.Random@33909752java.util.Random@55f96302java.util.Random@3d4eac69java.util.Random@42a57993java.util.Random@75b84c92java.util.Random@6bc7c054Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
      at java.util.ArrayList.rangeCheck(Unknown Source)
      at java.util.ArrayList.remove(Unknown Source)
      at apollo.exercises.ch08_collections.Ex1_BasicArrayList.main(Ex1_BasicArrayList.java:23)
  </code></pre>