参考: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 适合添加,删除操作

java 的collection的更多相关文章

  1. 模拟java.util.Collection一些简单的用法

    /* 需求:模拟java.util.Collection一些简单的用法! 注意:java虚拟机中并没有泛型类型的对象.泛型是通过编译器执行一个被称为类型擦除的前段转换来实现的. 1)用泛型的原生类型替 ...

  2. Java中Collection和Collections的区别(引用自:http://www.cnblogs.com/dashi/p/3597937.html)

      1.java.util.Collection 是一个集合接口(集合类的一个顶级接口).它提供了对集合对象进行基本操作的通用接口方法.Collection接口在Java 类库中有很多具体的实现.Co ...

  3. java中Collection类及其子类

    1:对象数组(掌握) (1)数组既可以存储基本数据类型,也可以存储引用类型.它存储引用类型的时候的数组就叫对象数组. 2:集合(Collection)(掌握) (1)集合的由来? 我们学习的是Java ...

  4. java 15-2 Collection的高级功能测试

    A:  boolean addAll(Collection c):添加一个集合的元素 ,所有的元素,无论是否重复 B:  boolean removeAll(Collection c):移除一个集合的 ...

  5. java 15-1 Collection集合的概述以及小功能介绍

     集合的由来:  我们学习的是面向对象语言,而面向对象语言对事物的描述是通过对象体现的,为了方便对多个对象进行操作,我们就必须把这多个对象进行存储.  而要想存储多个对象,就不能是一个基本的变量,而应 ...

  6. java集合——Collection接口

    Collection是Set,List接口的父类接口,用于存储集合类型的数据. 2.方法 int size():返回集合的长度 void clear():清除集合里的所有元素,将集合长度变为0 Ite ...

  7. [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)

    source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...

  8. Java API ——Collection集合类 & Iterator接口

    对象数组举例: 学生类: package itcast01; /** * Created by gao on 15-12-9. */ public class Student { private St ...

  9. 源码(03) -- java.util.Collection<E>

     java.util.Collection<E> 源码分析(JDK1.7) -------------------------------------------------------- ...

  10. JVM垃圾收集(Java Garbage Collection / Java GC)

    JVM垃圾收集(Java Garbage Collection / Java GC) Java7 Java8 JDK1.8之后将最初的永久代取消了,由元空间取代. 堆内存调优简介 public sta ...

随机推荐

  1. Windows(7/8/10)搭建kibana 6.x版本(elasticsearch的可视化服务)

    在搭建kibana之前,我们先了解下什么是kibana Kibana 是一款开源的数据分析和可视化平台,它是 Elastic Stack 成员之一,设计用于和 Elasticsearch 协作.您可以 ...

  2. 【HTML5】基于HTML5的高性能动画与游戏

    其实这篇文章类似版本早在12年就在网上各处出现了,也随着HTML5的兴起,HTML的新特性也是倍受开发者们追捧,自然相关HTML5的高性能动画与游戏的相关文章也是层出不穷的,笔者也是在12年接触的相关 ...

  3. Ambari架构及安装

    不多说,直接上干货! 1.什么是Ambari? 2.Ambari项目是由哪几部分构成的? 3.Ambari系统架构是如何组成的? 前言 Hadoop集群的管控一直是一个热门的话题,对于这样的一个应用场 ...

  4. 执行update, insert,delete 语句, 不返回结果集,(类型化参数)

    /// <summary> /// 执行update, insert,delete 语句, 不返回结果集,(类型化参数) /// </summary> /// <para ...

  5. JVM 内存区域划分

    一.运行时数据区包括哪几部分? 根据<Java虚拟机规范>的规定,运行时数据区通常包括这几个部分:程序计数器(Program Counter Register).Java栈(VM Stac ...

  6. dubbo之延迟连接及粘滞链接接

    延迟连接 延迟连接用于减少长连接数.当有调用发起时,再创建长连接.1 <dubbo:protocol name="dubbo" lazy="true" / ...

  7. 4星|《超级技术:改变未来社会和商业的技术趋势》:AI对人友好吗

    超级技术:改变未来社会和商业的技术趋势 多位专家或经济学人编辑关于未来的预测,梅琳达·盖茨写了其中一章.在同类书中属于水平比较高的,专家只写自己熟悉的领域,分析与预测有理有据而不仅仅是畅想性质. 以下 ...

  8. hdu,1028,整数拆分的理解

    #include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...

  9. WinMTR使用教程

    WinMTR下载链接:https://share.weiyun.com/53iPoC7 WinMTR官网连接:http://winmtr.net/download-winmtr/ WinMTR 使用方 ...

  10. ARM异常中断返回的几种情况

    在学习韦老师视频中中断异常部分时候,对于发生中断时需要执行的#保存异现场 #恢复现场 中的“返回”弄不清楚,查阅网络文章后,发现一篇概述我觉得我能理解的一篇如下:   重要基础知识:R15(PC)总是 ...