+ 1
Why java collection framework extends iterable interface even though it needs iterator object to go through the collection?
I'm very much confused about the relation between iterable and iterator interface.
1 Réponse
0
iterator can't be iterated using enhanced for loop, iterable can which is why collections extend them. iterator is actually an embedded classes inside many of the collection ADT. when used in enhanced for loop, iterator are automatically instantiated for you and call on to be iterated. it can't be done if it doesn't implement the iterable interface however