ArrayList 是List接口的实现类;底层的数据结构是数组,而LinkedList底层数据结构是双向循环链表。

  所以在查询时ArrayList效率高,增删时LinkedList高。由于List中有索引,可以在指定位置插入。在iterator迭代器取元素时,在调用Arraylist中的iterator()返回的其实是Iterator接口实例, Iterator it = new Str();

而Str是ArrayList的一个内部私有类,实现了Iterator接口,所以有next(),hasNext(),..方法。而ListIterator 是Iterator的子接口。在remove()或contain()方法中调用的是ArrayList中的equals比较对象是否存在。可以通过重写看到。

public class ArrayListTest {

public static void main(String[] args) {

List list = new MyList();

list.add(new Person5("haha",34));
list.add(new Person5("haha",34));
list.add(new Person5("haha",34));
//System.out.println(list.remove(new Person5("haha",34)));
System.out.println(list.remove(new Person5("haha",34)));

ListIterator it =list.listIterator();
while(it.hasNext()){
Person5 p = (Person5)it.next();
System.out.println(p.getName()+"--------"+p.getAge());
}
}

}

class Person6 {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Person6(String name, int age) {
super();
this.name = name;
this.age = age;
}

public int hashCode(){
System.out.println("----hashCode------");
return this.age;

}

public boolean equals(Object o){
Person5 p =(Person5)o;
System.out.println(this.name+"------equals---"+p.getName());
if(!(p instanceof Person5))
return false;
return this.name.equals(p.getName());
}

}

class MyList extends ArrayList{

@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
System.out.println("调用了remove方法----");
return super.remove(o);
}

}

ArrayList-VS-LinkedList的更多相关文章

  1. 深入理解java中的ArrayList和LinkedList

    杂谈最基本数据结构--"线性表": 表结构是一种最基本的数据结构,最常见的实现是数组,几乎在每个程序每一种开发语言中都提供了数组这个顺序存储的线性表结构实现. 什么是线性表? 由0 ...

  2. ArrayList,Vector,LinkedList

    在java.util包中定义的类集框架其核心的组成接口有如下:·Collection接口:负责保存单值的最大父接口 |-List子接口:允许保存重复元素,数据的保存顺序就是数据的增加顺序: |-Set ...

  3. Java数据结构之表的增删对比---ArrayList与LinkedList之一

    一.Java_Collections表的实现 与c不同Java已经实现并封装了现成的表数据结构,顺序表以及链表. 1.ArrayList是基于数组的实现,因此具有的特点是:1.有索引值方便查找,对于g ...

  4. C++模拟实现JDK中的ArrayList和LinkedList

    Java实现ArrayList和LinkedList的方式采用的是数组和链表.以下是用C++代码的模拟: 声明Collection接口: #ifndef COLLECTION_H_ #define C ...

  5. ArrayList与LinkedList用法与区别

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.  2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedLis ...

  6. ArrayList vs LinkedList vs Vector

    List概览 List,正如它的名字,表明其是有顺序的.当讨论List的时候,最好拿它跟Set作比较,Set中的元素是无序且唯一:下面是一张类层次结构图,从这张图中,我们可以大致了解java集合类的整 ...

  7. ArrayList 和 LinkedList 的区别

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.2.对于随机访问get和set,ArrayList优于LinkedList,因为LinkedList要移动 ...

  8. ArrayList和LinkedList的几种循环遍历方式及性能对比分析(转)

    主要介绍ArrayList和LinkedList这两种list的五种循环遍历方式,各种方式的性能测试对比,根据ArrayList和LinkedList的源码实现分析性能结果,总结结论. 通过本文你可以 ...

  9. ArrayList和LinkedList的几种循环遍历方式及性能对比分析

    最新最准确内容建议直接访问原文:ArrayList和LinkedList的几种循环遍历方式及性能对比分析 主要介绍ArrayList和LinkedList这两种list的五种循环遍历方式,各种方式的性 ...

  10. 集合中list、ArrayList、LinkedList、Vector的区别、Collection接口的共性方法以及数据结构的总结

    List (链表|线性表) 特点: 接口,可存放重复元素,元素存取是有序的,允许在指定位置插入元素,并通过索引来访问元素 1.创建一个用指定可视行数初始化的新滚动列表.默认情况下,不允许进行多项选择. ...

随机推荐

  1. Android 天天爱消除辅助

    简介 <天天爱消除>是一款移植于手游的消除类益智游戏,该游戏只有通过手机登录QQ跟微信才能进行,这样一来这款游戏必然会大红大紫. 功能 开发Android自动化触屏事件,录制操作脚本,实现 ...

  2. #include <memory>

    1 auto_ptr 2 unique_ptr 1 auto_ptr C++的auto_ptr所做的事情,就是动态分配对象以及当对象不再需要时自动执行清理. 使用std::auto_ptr,要#inc ...

  3. lodash的中文文档(不全)

    http://dingliang-321.iteye.com/blog/2184747

  4. python第三天---collections类

    collection系列 1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. 我们从中挑选一些相对常用的方法来举例: 在上面的例子我们可以看出,counter方法返 ...

  5. Minimum Inversion Number(归并排序)

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  6. Android重启应用程序代码

    Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPacka ...

  7. 部署SharePoint2013解决方案

    Add-SPSolutionInstall-SPSolution -Identity Grain2013.wsp -GACDeployment -CompatibilityLevel {14,15}  ...

  8. idea15破解

    注册方法:   注册码可以沿用14的,只是在 注册时选择 License server ,填 http://idea.lanyus.com ,然后点击 OK 14的话,网上可以找到一个,根据你的用户名 ...

  9. Struts学习之自定义拦截器

    * 所有的拦截器都需要实现Interceptor接口或者继承Interceptor接口的扩展实现类    * 要重写init().intercept().destroy()方法        * in ...

  10. WCF 接收、发送数据的大小及时间的设置

    <system.serviceModel> <bindings> <basicHttpBinding> <binding name="/> & ...