LinkedList取元素方法:
public E get(int index) {
return entry(index).element;
}
private Entry<E> entry(int index) {
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("Index: "+index+
", Size: "+size);
Entry<E> e = header;
if (index < (size >> 1)) {//这里折半
for (int i = 0; i <= index; i++)
e = e.next;
} else {
for (int i = size; i > index; i--)
e = e.previous;
}
return e;
}
ArrayList取元素方法:
public E get(int index) {
RangeCheck(index);
return (E) elementData[index];
}
LinkedList查询位置方法:
public int indexOf(Object o) {
int index = 0;
if (o==null) {
for (Entry e = header.next; e != header; e = e.next) {
if (e.element==null)
return index;
index++;
}
} else {
for (Entry e = header.next; e != header; e = e.next) {
if (o.equals(e.element))
return index;
index++;
}
}
return -1;
}
ArrayList查询位置方法:
public int indexOf(Object o) {
if (o == null) {
for (int i = 0; i < size; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = 0; i < size; i++)
if (o.equals(elementData[i]))
return i;
}
return -1;
}
分享到:
相关推荐
比较ArrayList,LinkedList,Vector三者随机读取,插入,删除性能。
ArrayList、LinkedList、Vector区别简介。
测试ArrayList和LinkedList的add方法
51. ArrayList LinkedList Set HashMap介绍.txt
NULL 博文链接:https://lf6627926.iteye.com/blog/1297695
1.List是接口类,ArrayList和LinkedList是List的实现类 2.ArrayList是动态数组(顺序表)的数据结构 3.LinkedList
Java面试题10.ArrayList LinkedList.mp4
关于arraylist和linkedList的区别
【Java面试题】ArrayList和LinkedList区别
对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。 ArrayList和LinkedList是两个集合类,用于存储一系列的对象引用(references)。例如我们可以用ArrayList来存储一系列的String...
2,随机访问的时候,ArrayList的效率比较高,因为LinkedList要移动指针,而ArrayList是基于 3,索引(index)的数据结构,可以直接映射到。 4,插入、删除数据时,LinkedList的效率比较高,因为ArrayList要移动数据。 ...
05丨ArrayList还是LinkedList?使用不当性能差千倍.html
合理运用ArrayList与LinkedList
ArrayList Vector LinkedList 区别与用法.
2.在ArrayList的中间插入或删除一个元素意味着这个列表中剩余的元素都会被移动 3.LinkedList不支持高效的随机元素访问 4.ArrayList的
下面小编就为大家带来一篇java 集合之实现类ArrayList和LinkedList的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
对比Vector、ArrayList、LinkedList1
ArrayList-LinkedList-源码.rar
1. List概述List,就如图名字所示一样,是元素的有序列表 3. ArrayList示例[java] view plain copy public sta