Using an iterator on a Vector
I am studying vectors and iterators and in the sample code I am looking at, a for loop is used and starts by initializing a variable by assigning a vector object's methods return value, which is an Iterator object, using the iterator method. Here is the code:
Code:
Vector v = new Vector(3);
v.add(1);
v.add(2);
v.add(3);
for ([B]Iterator i = v.iterator(); [/B]i.hasNext(); ) {
String name (String)i.next();
System.out.println(name);
}
I understand that the class Iterator is an interface, and that it only contains abstract methods for remove(), hasNext() and next(). I thought that the iterator() method of the vector, which is apparently inherited from the superclass List, would return an object containing those methods because the methods must be defined to be used by the new Iterator object.
So does the iterator() method of the vector return an object that has inherited the remove(), hasNext(), and next() methods? I couldn't find the code on Oracle's website that those three methods were defined. Thanks for your help!
-Derek Raimann