import java.util.HashSet;
import java.util.Iterator;
public class Test {
public static void main(String[] args) {
HashSet set = new HashSet();
for (int i = 0; i < 20; i++) {
set.add(i);
}
Iterator iterator = set.iterator();
while(iterator.hasNext()){
System.out.println((Integer)iterator.next());
}
}
}
用迭代器遍历