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.

How does the enhanced for statement work for arrays, and how to get an iterator for an array?

Given the following code snippet: int[] arr = {1, 2, 3}; for (int i : arr) System.out.println(i); I have the following questions: …

java arrays iterator foreach
Difference between Python's Generators and Iterators

What is the difference between iterators and generators? Some examples for when you would use each case would be helpful.

python iterator generator
How to pick just one item from a generator?

I have a generator function like the following: def myfunct(): ... yield result The usual way to call this function would …

python iterator generator python-2.x
hasNext in Python iterators?

Haven't Python iterators got a hasNext method?

python iterator
C++ STL Vectors: Get iterator from index?

So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need …

c++ stl vector iterator
How to iterate over a std::map full of strings in C++

I have the following issue related to iterating over an associative array of strings defined using std::map. -- snip …

c++ dictionary iterator std stdmap
Adding elements to a collection during iteration

Is it possible to add elements to a collection while iterating over it? More specifically, I would like to iterate …

java iterator
Getting number of elements in an iterator in Python

Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating …

python iterator
What is the difference between iterator and iterable and how to use them?

I am new in Java and I'm really confused with iterator and iterable. Can anyone explain to me and give …

java iterator iterable
Ruby: How to iterate over a range, but in set increments?

So I'm iterating over a range like so: (1..100).each do |n| # n = 1 # n = 2 # n = 3 # n = 4 # n = 5 end But what I'd …

ruby iterator increment