Iterator 关键字,用于集合的遍历
import java.util.*;
public class IteratorKeyWord {
public static void main(String[] args) {
Collection c = new ArrayList<Object>();
c.add("hello");
c.add(new Integer(5));
System.out.println(c.size());
System.out.println(c);
Iterator i = c.iterator();
while (i.hasNext()) {
Object s = (Object)i.next();
if (s instanceof String) {
String str = (String)s;
System.out.println("i.next is String = " + str);
}else {
System.out.println("i.next is Interger = " + s.toString());
}
}
c.remove("hello");
for (Object o : c ) {
System.out.println(o);
}
}
}