一.
当需要频繁进行元素的增加和删除时,最好使用LinkedList,因为其不需要元素的移动,只需要改变前后的引用;
当需要频繁进行元素查找时,最好使用ArrayList,因为其底层采用数组实现,数组是连续存放的,查找速度非常快。二.
System.arraycopy()--------从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束。
//数组的复制
public class CopyArray {
public static void main(String[] args) {
Integer[] a = new Integer[] { 1, 2, 3, 4, 5, 6 };
Integer[] b = new Integer[a.length * 2];
System.arraycopy(a, 0, b, 0, a.length);
b[6] = 7;//可以看着是数组的扩充
for (Integer integer : b) {
System.out.println(integer);
}
}
}
三.
ArrayList与Vector的区别
1.ArrayList的所有方法都是非同步的(not synchronized)2.Vector的很多public方法都是同步的(synchronized)
本文讨论了ArrayList与LinkedList在不同操作场景下的适用性:对于频繁增删的场景推荐使用LinkedList,而对于频繁查找则推荐使用ArrayList。此外,还介绍了System.arraycopy()方法用于数组复制,并对比了ArrayList与Vector的特点。

被折叠的 条评论
为什么被折叠?



