title: Iterate through Linked List in Java
body: <p>Say, I have two references to an Object in a LinkedList List1:</p>
  
  <pre><code>LinkedList&lt;Object&gt; List1 = new LinkedList&lt;Object&gt;();
  Object first;
  Object last;
  </code></pre>
  
  <p>I don't want to use the list index of these objects to refer to them, because the length of my list changes. I think this would not work.
  Now I want to iterate through the sublist defined by first and last, where first defines the beginning of the sublist in List1 and last defines the end of the sublist in List1.</p>
  
  <p>My problem now is that AFAIK I can't do something like </p>
  
  <pre><code>while (current != last){
  // do something
  current = someiterator.next();
  
  }
  </code></pre>
  
  <p>because I'm comparing two objects that in general will point to different locations. Furthermore, I also can't compare the references by their value, because the list may have one value appearing several times. 
  So how can I iterate through this sublist of List1?</p>