参考:http://skyuck.iteye.com/blog/526358

https://www.tutorialspoint.com/java/java_collections.htm

Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties to store and manipulate groups of objects. Although these classes were quite useful, they lacked a central, unifying theme. Thus, the way that you used Vector was different from the way that you used Properties.

The collections framework was designed to meet several goals, such as −

  • The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) were to be highly efficient.

  • The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability.

  • The framework had to extend and/or adapt a collection easily.

Towards this end, the entire collections framework is designed around a set of standard interfaces. Several standard implementations such as LinkedList, HashSet, and TreeSet, of these interfaces are provided that you may use as-is and you may also implement your own collection, if you choose.

A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following −

  • Interfaces − These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.

  • Implementations, i.e., Classes − These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.

  • Algorithms − These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.

In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections.

-------------------------------------------------------------------------------------

在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为方便。这些接口和类有很多对抽象数据类型操作的API,而这是我们常用的且在数据结构中熟知的。例如Map,Set,List等。并且Java用面向对象的设计对这些数据结构和算法进行了封装,这就极大的减化了程序员编程时的负担。程序员也可以以这个集合框架为基础,定义更高级别的数据抽象,比如栈、队列和线程安全的集合等,从而满足自己的需要。

Java2的集合框架,抽其核心,主要有三种:List、Set和Map。如下图所示:

需要注意的是,这里的 Collection、List、Set和Map都是接口(Interface),不是具体的类实现。 List lst = new ArrayList(); 这是我们平常经常使用的创建一个新的List的语句,在这里, List是接口,ArrayList才是具体的类。

常用集合类的继承结构如下: 
Collection<--List<--Vector 
Collection<--List<--ArrayList 
Collection<--List<--LinkedList 
Collection<--Set<--HashSet 
Collection<--Set<--HashSet<--LinkedHashSet 
Collection<--Set<--SortedSet<--TreeSet 
Map<--SortedMap<--TreeMap 
Map<--HashMap

-----------------------------------------------SB分割线------------------------------------------

List: 
List是有序的Collection,使用此接口能够精确的控制每个元素插入的位置。用户能够使用索引(元素在List中的位置,类似于数组下 >标)来访问List中的元素,这类似于Java的数组。

Vector: 
基于数组(Array)的List,其实就是封装了数组所不具备的一些功能方便我们使用,所以它难易避免数组的限制,同时性能也不可能超越数组。所以,在可能的情况下,我们要多运用数组。另外很重要的一点就是Vector是线程同步的(sychronized)的,这也是Vector和ArrayList 的一个的重要区别。

ArrayList: 
同Vector一样是一个基于数组上的链表,但是不同的是ArrayList不是同步的。所以在性能上要比Vector好一些,但是当运行到多线程环境中时,可需要自己在管理线程的同步问题。

LinkedList: 
LinkedList不同于前面两种List,它不是基于数组的,所以不受数组性能的限制。 
它每一个节点(Node)都包含两方面的内容: 
1.节点本身的数据(data); 
2.下一个节点的信息(nextNode)。 
所以当对LinkedList做添加,删除动作的时候就不用像基于数组的ArrayList一样,必须进行大量的数据移动。只要更改nextNode的相关信息就可以实现了,这是LinkedList的优势。

List总结:

  • 所有的List中只能容纳单个不同类型的对象组成的表,而不是Key-Value键值对。例如:[ tom,1,c ]
  • 所有的List中可以有相同的元素,例如Vector中可以有 [ tom,koo,too,koo ]
  • 所有的List中可以有null元素,例如[ tom,null,1 ]
    • 基于Array的List(Vector,ArrayList)适合查询,而LinkedList 适合添加,删除操作

最新文章

  1. 如何执行字符串的PHP代码
  2. 类似UC天气下拉和微信下拉眼睛头部弹入淡出UI交互效果(开源项目)。
  3. ubuntu samba服务器多用户配置【转】
  4. Linux vi入门必备
  5. js动态添加事件
  6. oracle调优 浅析关联设计
  7. 《Linux Device Drivers》第十章 中断处理——note
  8. Android ActionBar应用实战,高仿微信主界面的设计
  9. maxContainerCapability 设置不足
  10. route-over VS mesh-under
  11. ACM-最小生成树之畅通project——hdu1863
  12. matlab怎么查看已安装哪些工具箱和…
  13. Hadoop问题:java.net.SocketException: Network is unreachable
  14. 数学建模:2.监督学习--分类分析- KNN最邻近分类算法
  15. springboot打war包需要注意事项
  16. 【推荐】关于JS中的constructor与prototype【转】
  17. Nginx反向代理+Tomcat+Springmvc获取用户访问ip
  18. C# 实现屏幕截屏
  19. UltraEdit常用设置及快捷键
  20. css3网站收集

热门文章

  1. Prime Ring Problem -- 第一个真正意义上的 搜索
  2. MAC应用无法打开或文件损坏的处理方法
  3. JavaScript 计时器
  4. JavaScript--Array 数组对象
  5. 355 Design Twitter 设计推特
  6. python导入包出错:ImportError: No module named XXXXX
  7. Squirrel的安装(windows上Phoneix可视化工具)
  8. Mybatis的Dao向mapper传多个参数(三种解决方案)
  9. Android 升级安装APK兼容Android7.0,解决FileUriExposedException
  10. 在PHP中调用php_ssh实现远程登陆linux服务器并执行shell脚本。