Yield Return In Java

后端 未结 10 1256
春和景丽
春和景丽 2020-12-13 23:13

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 yield return insid

10条回答
  •  醉话见心
    2020-12-13 23:47

    Am I missing something here? There is already java.util.LinkedList, it is fully generics-enabled, and it has a method which returns an Iterator.

    If you really want to re-invent the wheel, I'd suggest you look into to creating a LinkedListIterator class, probably implementing ListIterator. It would remember its current position within the linked list and advance it on each successive call.

提交回复
热议问题