官网对 Collection 的定义解释为
The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements.
Some collections allow duplicate elements and others do not. Some are ordered and others unordered.
The JDK does not provide any direct implementations of this interface:
it provides implementations of more specific subinterfaces like Set and List.
This interface is typically used to pass collections around and manipulate them where maximum generality is desired.
集合层次结构中的根接口。集合表示一组对象,称为其元素。有些集合允许复制元素,有些则不允许。
有些是有序的,有些是无序的。JDK没有提供该接口的任何直接实现:它提供了更具体的子接口(如Set和List)的实现。
此接口通常用于在需要最大通用性的地方传递和操作集合。
List类型特征总结
List类型
线程是否安全
底层数据结构
CRUD的效率
ArrayList
否
Object数组
因为实现了RandomAccess接口,拥有随机快速访问的能力,基于底层数据结构由数组实现,可以通过下标访问,所以修改与查询的效率高;但是如果删除某个元素比如第 i 个元素,则要将 i 之后的元素都向前移一位以保证顺序表的正确,增加也是一样,要移动多个元素,所以多次删除增加的话是很低效的;
官网对 Map 的定义解释为:
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
This interfacetakestheplaceoftheDictionaryclass, whichwasatotallyabstractclassratherthananinterface.
TheMapinterfaceprovidesthreecollectionviews, whichallowamap’scontentstobeviewedasasetofkeys,
collectionofvalues, orsetofkey-valuemappings. Theorderofamapisdefinedastheorderinwhichtheiteratorsonthemap’scollectionviewsreturntheirelements. Somemapimplementations, liketheTreeMapclass, makespecificguaranteesastotheirorder; others, like the HashMap class, donot.
将键映射到值的对象。地图不能包含重复的键;每个键最多可以映射到一个值。
这个接口代替了Dictionary类,Dictionary类是一个完全抽象的类,而不是接口。
Map接口提供了三个集合视图,它们允许将映射的内容视为一组键、值的集合或一组键-值映射。
映射的顺序定义为映射集合视图上的迭代器返回其元素的顺序。
一些映射实现,比如TreeMap类,对它们的顺序做了特定的保证;而其他类,如HashMap类,则没有。