title: How do I set an element in a linked list by the index?
body: <p>So I need to make this method to set an element a certain object by index. For example I would input index 5, and it would set whatever I chose for the object in index 5. I'm using a linked list for this. Here's the method so far..</p>
  
  <pre><code>public void setElement(int index, Object element) {
     ListIterator iterator = listIterator();   
  }
  </code></pre>
  
  <p>I have no clue how to do this. I'm using nodes by the way. Also the ListIterator class is just the ListIterator interface. It has the methods of next, hasNext, add, remove and set. I just don't know how I would go about doing this. Could someone guide me in the right direction?</p>
  
  <p>EDIT: I'm using my own implemented link list.</p>
  
  <p>Here's what I just wrote which seems like I'm on the right track, but it's still not working.</p>
  
  <pre><code> public void setElement(int index, Object element) {
         ListIterator iterator = listIterator();
         int count = 0;      
         while(iterator.hasNext()) {
             count++;
             if(count == index){
                 iterator.set(element);
             }
         }       
     }
  </code></pre>