做网站编辑的时候没保存怎么,网站qq未启用,酒店网站搜索引擎优化方案,市场seo是什么List是有序、可重复的容器。 有序#xff1a; List中每个元素都有索引标记。可以根据元素的索引标记(在List中的位置)访问 元素#xff0c;从而精确控制这些元素。 可重复#xff1a; List允许加入重复的元素。更确切地讲#xff0c;List通常允许满足 e1.equals(e2) 的元素…List是有序、可重复的容器。 有序 List中每个元素都有索引标记。可以根据元素的索引标记(在List中的位置)访问 元素从而精确控制这些元素。 可重复 List允许加入重复的元素。更确切地讲List通常允许满足 e1.equals(e2) 的元素重复加入容器。 List接口常用的实现类有3个ArrayList、LinkedList和Vector。
1.ArrayList ArrayList底层是用数组实现的存储。 特点查询效率高增删效率低线程不安全。我们一般使用它。 ArrayList底层使用Object数组来存储元素数据。所有的方法都围绕这个核心的Object数组来开展。
2.LinkedList LinkedList底层用双向链表实现的存储。特点查询效率低增删效率高线程不安全。 双向链表也叫双链表是链表的一种它的每个数据节点中都有两个指针分别指向前一个节点和后一个节点。 所以从双向链表中的任意一个节点开始都可以很方便地找到所有节点。
3.Vector Vector底层是用数组实现的List相关的方法都加了同步检查因此“线程安全,效率低”。 比如copyInto方法就增加了synchronized同步标记。
使用原则ArrayList、LinkedList、Vector
需要线程安全时用Vector。不存在线程安全问题时并且查找较多用ArrayList(一般使用它)。不存在线程安全问题时增加或删除元素较多用LinkedList。
测试案例
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;public class day17 {public static void main(String[] args) {ListString arrayList new ArrayList();ListString linkedList new LinkedList();ListString vector new Vector();ListInteger arrayList2 new ArrayList();ListInteger linkedList2 new LinkedList();ListInteger vector2 new Vector();ListString arrayList3 new ArrayList();ListString linkedList3 new LinkedList();ListString vector3 new Vector();ListString list1 Arrays.asList(黄,河,之,水,天,上,来,奔,流,到,海,不,复,回,黄,河,之,水,天,上,来,奔,流,到,海,不,复,回);ListInteger list2 Arrays.asList(2 , 1 , 4 , 3 , 6 , 5 ,7 , 14, 13 ,12 , 11 ,10 , 9 , 8,2 , 1 , 4 , 3 , 6 , 5 ,7 , 8 , 9 ,10 , 11 ,12 , 13 , 14);ListString list3 Arrays.asList(2 , 1 , 4 , 3 , 6 , 5 ,7 , 14, 13 ,12 , 11 ,10 , 9 , 8,2 , 1 , 4 , 3 , 6 , 5 ,7 , 8 , 9 ,10 , 11 ,12 , 13 , 14);arrayList.addAll(list1);System.out.println(arrayList:arrayList);arrayList2.addAll(list2);System.out.println(arrayList2:arrayList2);arrayList3.addAll(list3);System.out.println(arrayList3:arrayList3);System.out.println(-------------------------------------------);linkedList.addAll(list1);System.out.println(linkedList:linkedList);linkedList2.addAll(list2);System.out.println(linkedList2:linkedList2);linkedList3.addAll(list3);System.out.println(linkedList3:linkedList3);System.out.println(-------------------------------------------);vector.addAll(list1);System.out.println(vector:vector);vector2.addAll(list2);System.out.println(vector2:vector2);vector3.addAll(list3);System.out.println(vector3:vector3);System.out.println(-------------------------------------------);}
}
测试输出
arrayList:[黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回, 黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回]
arrayList2:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
arrayList3:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
-------------------------------------------
linkedList:[黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回, 黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回]
linkedList2:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
linkedList3:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
-------------------------------------------
vector:[黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回, 黄, 河, 之, 水, 天, 上, 来, 奔, 流, 到, 海, 不, 复, 回]
vector2:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
vector3:[2, 1, 4, 3, 6, 5, 7, 14, 13, 12, 11, 10, 9, 8, 2, 1, 4, 3, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14]
-------------------------------------------