集合:
1:单列:Collection 接口
可重复:List 接口
ArrayList 实现类
LinkedList 实现类
不可重复:Set 接口
HashSet 实现类
TreeSet 实现类
2:双列:Map 接口
HashMap 实现类
使用迭代器Iterator循环输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import java.util.ArrayList; import java.util.Collection; import java.util.Iterator;
public class IteratorDemo {
public static void main(String[] args) { // TODO Auto-generated method stub Collection<String> c=new ArrayList<String>(); c.add("1"); c.add("2"); c.add("3"); Iterator<String> it= c.iterator(); while(it.hasNext()) { System.out.println(it.next()); } System.out.println(c); }
}
|