常用容器(Collection)实现类总结(零)

容器(Collection) 层次结构中的根(root)接口。Collection 表示一组对象,这些对象也称为 collection 的元素。一些 collection 允许有重复的元素,而另一些则不允许。一些 collection 是有序的,而另一些则是无序的。JDK 不提供此接口的任何直接 实现:它提供更具体的子接口(如 Set 和 List)实现。此接口通常用来传递 collection,并在需要最大普遍性的地方操作这些 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.)

其中,常用的具体类有:

  • ArrayList:底层实现为数组(Array),可以重复放置元素,且为线性排列。优点是查找方便,缺点是增、删速率低。
  • LinkedList:底层实现为链表(Link list),优点是删除和添加的效率很高,但随机访问元素时效率较ArrayList类低。
  • HashMap:通过键值对(Key—Value)映射的数据结构(类似于字典的用法),且Key有且唯一,但是一个Key可以一对多个Value,细节后续讨论。优点是可以通过Key快速查找并操作相关数据,很方便。
  • HashSet:不允许重复的对象传入,且不能保证传入数据能够有序迭代( It makes no guarantees as to the iteration order of the set)。优点是HashSet利用Hash函数进行了查询效率上的优化。
posted @ 2017-03-24 13:55  NOthingAJ  阅读(235)  评论(0编辑  收藏  举报