双向链表既能指向下一个元素,也能指向上一个元素。
4.红黑树查询速度非常快。
5、List集合list的特点:
(1)有序的集合,存储元素和取出元素的顺序是一致的(存储123,取出123)
(2)有索引,包含了一些带索引的方法
(3)允许存储重复的元素。
java.util.list接口 extends Collection接口
List接口中带索引的方法(特有)
public void add(int index, E element):将指定的元素,添加到该集合中指定的位置上
public E get(int index) :返回集合中指定位置的元素
public E remove(int index): 移除列表中指定位置的元素,返回的是被移除的元素。
public E set(int index, E element):用指定元素替换集合中指定位置的元素,返回值是被替换的元素。
注意:
操作索引的时候,一定要防止索引越界异常
IndexOutOfBoundException:索引越界异常,集合会报
ArrayIndexOutOfBoundException:数组索引越界异常
StringIndexOutOfBoundsException:字符串索引越界异常
底层是一个数组的结构,查询快,但是增删慢。多线程,查询快
7.linkedListDemo01linkedList.java
package linkedList;
import java.util.linkedList;
import java.util.List;
public class Demo01linkedList {
public static void main(String[] args) {
//创建的时候不能用多态
linkedList linked = new linkedList<>();
linked.add("a");
linked.add("b");
linked.add("c");
System.out.println(linked);//[a, b, c]
linked.addFirst("d");
System.out.println(linked);//[d, a, b, c]
linked.addLast("e");
System.out.println(linked);//[d, a, b, c, e]
linked.push("f");
System.out.println(linked);//[f, d, a, b, c, e]
System.out.println(linked.getFirst());//f
System.out.println(linked.getLast());//e
System.out.println(linked.removeFirst());//f
System.out.println(linked.removeLast());//e
System.out.println(linked);//[d, a, b, c]
System.out.println(linked.pop());//d
System.out.println(linked.isEmpty());//false
}
}
8.Vector
同步,单线程,速度慢



