title: Incorrect Output for List
body: <p>I'm doing a beginner Java tutorial on Lists, and am presented with the below problem</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 alphabet = "abcdefghijklmnopqrstuvwxyz";
              StringBuilder sb = new StringBuilder();
              sb.append(alphabet.charAt(rand.nextInt(alphabet.length())));
              String randy = sb.toString();
              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()-1);
  
          for (int i = 0; i &lt; list.size(); i++){
              System.out.println(list.get(i));
          }
      }
  }
  </code></pre>
  
  <p>I have managed to generate an output, but it is incorrect :(</p>
  
  <p>For my first <code>System.out.print(list.get(i));</code> I'm trying to get an output for 10 String values, but I get 12.</p>
  
  <p>Sample output: <code>nhgacqhlejph</code></p>
  
  <p>And when I run the second <code>System.out.println(list.get(i));</code>, I get an output for 8 String Values, which is correct if I started out with 10 in the list, but I have 12, so it means that 4 values were removed :/</p>
  
  <p>Sample output:</p>
  
  <pre><code>g
  a
  c
  q
  h
  l
  e
  j
  </code></pre>
  
  <p>Does anyone know where I went wrong with my code? </p>
  
  <p>To repeat:</p>
  
  <ol>
  <li><p>I wish to get 10 String values of one letter each from the first <code>System.out.print(list.get(i));</code>  </p></li>
  <li><p>I also want to get 2 less String values from the original list by running the second <code>System.out.println(list.get(i));</code></p></li>
  </ol>