Iterator in Java.
Posted
by theband
on Stack Overflow
See other posts from Stack Overflow
or by theband
Published on 2010-05-22T19:59:37Z
Indexed on
2010/05/22
20:11 UTC
Read the original article
Hit count: 211
javadoc
What is Iterator and collections? Does these two have any relations?
// the interface definition
Interface Iterator {
boolean hasNext();
Object next(); // note "one-way" traffic
void remove();
}
// an example
public static void main (String[] args){
ArrayList cars = new ArrayList();
for (int i = 0; i < 12; i++)
cars.add (new Car());
Iterator it = cats.iterator();
while (it.hasNext())
System.out.println ((Car)it.next());
}
Does the Interface Iterator has these method names alone predefined or its user defined?. What does these four lines below actually tell?
cars.add (new Car());
Iterator it = cats.iterator();
while (it.hasNext())
System.out.println ((Car)it.next());
Thanks i am going through a book in collections.
© Stack Overflow or respective owner