title: Yield Return In Java
body: <p>I've created a linked list in java using generics, and now I want to be able to iterate over all the elements in the list. In C# I would use <code>yield return</code> inside the linked list while going over the list of elements contained in the list.</p>
  
  <p>How would I go about creating a java version of the above where I can iterate over all the items contained in the linked list?</p>
  
  <p>I'm looking to be able to write code ala</p>
  
  <pre><code>LinkedList&lt;something&gt; authors = new LinkedList&lt;something&gt;();
  for (Iterator&lt;something&gt; i = authors.Values ; i.HasNext())
        doSomethingWith(i.Value);
  </code></pre>
  
  <p>And was thinking that the Value 'property'/method would consist of code resembling</p>
  
  <pre><code>LinkedListObject&lt;something&gt; current = first;
  While (current != null){
   yield return current.getValue();
   current = current.getNext()
  }
  </code></pre>
  
  <p>Edit: Notice that I'm not interested in using any 3rd party APIs. Built-in java functionality only.</p>