1.Hold Objects
用于装载对象的可以分为Array和Container。
Array元素不仅可以为对象,还可以为基本类型。Container元素不可以为基本类型。
Container分类为Collection和Map,其中Collection包括List,Set,Queue。
Collection : a sequence of individual elements with one or more rules applied to them. AListmust hold the elements in the way that they were inserted, aSet cannot have duplicate elements, and a Queue produces the elements in the order determined by a queuing discipline (usually the same order in which they are inserted).
Map : a group of key-value object pairs, allowing you to look up a value using a key.
2.Collection Add Elements
向Collection添加元素时,可以调用成员函数Collection.addAll(),或者java.util包下的Collections.addAll()
Collection.addAll()要求参数为Collection。
Collections.addAll()更加灵活,参数可以为Collection,Array,或comma-seperated的元素
Arrays.asList用户将Array转化为Collection(List),可以作为使用Collection API的桥梁。但注意两点
(1).返回的List为Fix-Sized,任何add和remove操作都将导致Unsupported Operation Exception
(2).根据成员的类型,Best-Guess 返回List的类型。这可能与预期的类型要求不同
3.List
对List接口的常见实现包括ArrayList和LinkedList。
在List中Add、Remove、indexOf等操作时,通过调用对象的equals()方法实现的。
4.Iterator
实现iterable接口,需要实现Iterator<E> iterator()方法。Iterator类需要实现hasNext(), next()方法。这个也是能够使用foreach语法的前提。
List接口中,还实现了ListIterator<E> listIterator()方法。可以双向遍历。