Does calling anIterable.iterator()
return a new or an existing Iterator? Does it depend on the Iterable implementation?
More specifically, would the following code work as expected (i.e. the inner loop would iterate from the beginning)?
for (Item itemA : items) {
for (Item itemB : items) {
....
}
}
If not, than how can this be achieved on an Iterable
?
Depends how iterable interface is implemented. Generally the collection frameworl classes returns new instance.