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 开发ListView适配器优化

    我们都知道Android中Adapter的作用就是ListView界面与数据之间的桥梁,当列表里的每一项显示到页面时,都会调用Adapter的getView方法返回一个View.想过没有? 在我们的列 ...

  2. iphone5升级到iOS7时出现“This device isn't eligible for the requested build”错误

    因为工作的需要我需要把自己的手机升级到iOS7,安装苹果的升级顺序总是报This device isn't eligible for the requested build错误,搜索相关的文章我的错误 ...

  3. SDOTOJ2088 refresh的停车场(栈和队列)

     refresh的停车场 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit S ...

  4. 最终有SpringMvc与Struts2的对照啦

    眼下企业中使用SpringMvc的比例已经远远超过Struts2,那么两者究竟有什么差别,是非常多刚開始学习的人比較关注的问题,以下我们就来对SpringMvc和Struts2进行各方面的比較: 1. ...

  5. _视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  6. jQuery的三种$()

    参考脚本之家“http://www.jb51.net/article/21660.htm”   $号是jQuery“类”的一个别称,$()构造了一个jQuery对象.所以,“$()”可以叫做jQuer ...

  7. ul li 好友列表

    <div class="col-md-4 mt"> <div class="friend-list"> <h4 class=&qu ...

  8. BZOJ 1491: [NOI2007]社交网络( floyd )

    floyd...求最短路时顺便求出路径数. 时间复杂度O(N^3) ------------------------------------------------------------------ ...

  9. 关于Python网络爬虫实战笔记③

    Python网络爬虫实战笔记③如何下载韩寒博客文章 Python网络爬虫实战笔记③如何下载韩寒博客文章 target:下载全部的文章 1. 博客列表页面规则 也就是, http://blog.sina ...

  10. 机器学习算法实现(R&Python code)

    Machine Learning Algorithms Machine Learning Algorithms (Python and R) 明天考试,今天就来简单写写机器学习的算法 Types Su ...