一、遍历Collection的两种方法:
-
Iterator迭代器:
Collection coll = new Collection(); coll.add(123); coll.add(456); coll.add(new Person("Jerry",20)); coll.add(new String("Tom")); coll.add(false); Iterator iterator = coll.iterator(); while(iterator.hasNext()){ while (iterator.hasNext()){ System.out.println(iterator.next()); } } }
-
foreach方法:
for(Object obj : coll){ System.out.println(obj); } }
二、Collection子接口之一:List接口:有序的、可重复的
-
ArrayList
增:add(Object obj)
删:remove(int index) / remove(Object obj)
改:set(int index, Object ele)
查:get(int index)
插:add(int index, Object ele)
长度:size()
遍历:① Iterator迭代器方式
② 增强for循环
③ 普通的循环 -
LinkedList
体现了双向链表的思翔