Paul Clapham wrote:... if you wanted you could print out its name. Like so:
Jesse Silverman wrote:Everyone keeps telling you to code to Interface, not Implementation.
From Java1.2, when the Collections Framework was introduced, until Java1.4, Collection had an iterator() method, which as Jesse says, returns an Iterator, whose details you can find from this Java7 API link. In Java5, the for‑each loop wass introduced, which can iterate an Iterable, or an array, and the iterator() method was moved from Collection to Iterable. Since Collection extends Iterable, the removed method wass replaced there by inheritance. If you omit any methods in any non‑abstract Collection, the code will fail to compile. So, as Jesse says, all those classes must have an iterator() method.
Jesse Silverman wrote:. . . Every class that implements Collection is guaranteed and required to provide a working implementation of:
As Jesse says, that must return an instance of a concrete implementation of Iterator, and that will have all the methods specified in those interfaces.
. . .
Iterator<Integer> i = a.iterator();
Agree. You don't need to know such things, but they can be interesting to know about. Different List implementations supply different Iterator implementations.I shall let you find out whether the code for those implementations is in src.zip.
. . . it is not required to know this, . . .
Campbell Ritchie wrote:Search your Java® installation folder for ....