I’d checked the java source API of jdk6 and jdk7. In there in jdk7 ArrayList class have an private inner class which implements the Iterator interface but in jdk6 there’s no such thing, even I don’t found the iterator() which will return the instance of Iterator.
Can anybody tell me prior to jdk7 how the instance of Iterator is received and where the methods of Iterator interface are implemented?
In Java 6, the iterator implementation class is a private inner class in
AbstractListclass (the superclass ofArrayList). Search for the identifierItrin the source code.Why are the Java 6 and Java 7 versions different? Well, this comment in the Java 7 source code is a big clue:
I’ll leave it to the reader to research the nature of those optimizations. (Read the source Luke!)