Top "Iterator" questions

An iterator is an object-oriented programming pattern that allows traversal through a collection, agnostic of the actual implementation or object addresses in physical memory.

Iterator vs for

I was asked in an interview what is the advantage of using iterator using for loop or what is the …

java for-loop iterator
Circular list iterator in Python

I need to iterate over a circular list, possibly many times, each time starting with the last visited item. The …

python list iterator
Is there an expression for an infinite generator?

Is there a straight-forward generator expression that can yield infinite elements? This is a purely theoretical question. No need for …

python iterator generator infinite-loop
Iterate an iterator by chunks (of n) in Python?

Can you think of a nice way (maybe with itertools) to split an iterator into chunks of given size? Therefore …

python iterator
escaping the .each { } iteration early in Ruby

code: c = 0 items.each { |i| puts i.to_s # if c > 9 escape the each iteration early - and do …

ruby loops iterator enumerator
How do you iterate through a list of objects?

I have a User class that has a String username in it. I have a list of users that I'm …

struts2 iterator
Is if(items != null) superfluous before foreach(T item in items)?

I often come across code like the following: if ( items != null) { foreach(T item in items) { //... } } Basically, the if condition …

c# iterator foreach iteration
java.util.NoSuchElementException using iterator in java

I'm trying to iterate through a list using the iterator over my list of Logs. The goal is to search …

java iterator nosuchelementexception
Java, Using Iterator to search an ArrayList and delete matching objects

Basically, the user submits a String which the Iterator searches an ArrayList for. When found the Iterator will delete the …

java iterator foreach-loop-container
How do you iterate over a string by character

I have a string and I need to scan for every occurrence of "foo" and read all the text following …

string iterator rust