title: Index out of bounds exception when using recursion in linkedlists
body: <p>So for the most part, I'm required to count the number of elements in the linkedlists using the recursion method. However, I'm being thrown an out of bounds exception. I can't seem to fix the issue.</p>
  
  <pre><code>import java.util.*;
  import java.util.LinkedList;
  
  public class ListCount {
  public static LinkedList&lt;String&gt; ll = new LinkedList&lt;String&gt;();
  
  public static void main(String[] args) {
      int size = 0;
  LinkedList&lt;String&gt; list = new LinkedList&lt;String&gt;();
  list.add("Hi");
  list.add("I");
  list.add("am");
  list.add("a");
  list.add("programmer");
  list.add("and");
  list.add("I");
  list.add("am");
  list.add("currently");
  list.add("working");
  list.add("on");
  list.add("an");
  list.add("assignment");
  list.add("that");
  list.add("is");
  list.add("based");
  list.add("on");
  list.add("linkedlists");
  list.add("for");
  list.add("java");
  
  ll = list;
  
  countsize(size);
  
  
  }
      public static int countsize(int somevalue)
      {
     Iterator next = ll.listIterator(somevalue);  
      {
          if (next == null)
      {
        return 0; 
      }
      else 
      {
      countsize(somevalue + 1);
      }
     System.out.println(somevalue);
      }
    return 0;
  }    
  </code></pre>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 21, Size: 20
      at java.util.LinkedList.checkPositionIndex(Unknown Source)
      at java.util.LinkedList.listIterator(Unknown Source)
      at ListCount.countsize(ListCount.java:44)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.countsize(ListCount.java:52)
      at ListCount.main(ListCount.java:38)
  </code></pre>