1,Collection 集合特点:这个是一个单列集合体系:
其中包含了,List和set集合体系;
再其中,List 与 Set 的区别:
- List,包含了ArrayList,LinkedList;
- 有索引
 - 元素可以重复
 - 存储和取出有顺序
 
 Set,包含了HashSet,TreeSet;LinkedHashSet;
问:为什么要将集合中的数据放到数组中?
添加:add
collection.add("1");
删除:clear
collection.clear();
删除特定对象:remove
boolean remove = collection.remove("1");
判断当前集合是否存在特定对象:contains
boolean contains = collection.contains("1");
判断集合是否为空:isEmpty
boolean empty = collection.isEmpty();
返回集合个数(长度):size
int size = collection.size();
将数组存放到数组:toArray ```java Object[] objects = collection.toArray(); for (int i = 0; i < objects.length; i++) { Object o=objects[i]; System.out.println(o); }
<a name="R8ube"></a>## 4,Collection的遍历:因为在collection的体系内中的Set集合无索引,因此,无法使用循环来遍历集合;<br />那么,在Colletion提供了一种叫迭代器的方式来遍历集合:<a name="Udbgs"></a>### 1,迭代器的使用:([注意:迭代器只能获取元素,不能修改或删除元素!](https://www.yuque.com/liangmingxi/xte5fo/kv37we))1. 获取迭代器:**Iterator**```javaIterator<String> s1 = collection.iterator();//s1 是变量名
2. 循环判断是否有元素;2. 获取元素:
//判断是否有下一元素迭代器变量名.hasNext()//判断是否有下一个元素while (s1.hasNext()){String s=s1.next();System.out.println(s);}
2,增强for循环遍历集合:
详情请见:增强for循环;

