当前位置:天才代写 > tutorial > JAVA 教程 > 从源代码看ArrayList和Vector的真正区别

从源代码看ArrayList和Vector的真正区别

2017-11-11 08:00 星期六 所属: JAVA 教程 浏览:327

本日正悦目到了这个对象,一直都是看别人的资料,抉择本身亲自看看源代 码。JDK版本为 6.0_04 的

1 声明没有任何区别

public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable;
public class Vector<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable;

2 结构器要领,默认都是10个初始化容量。Vector带每次增加容量的参数

public ArrayList(int initialCapacity);
public Vector(int initialCapacity);
public Vector(int initialCapacity, int capacityIncrement);

3 add等要领,Vector是同步的要领

ArrayList
public boolean add(E e);
Vector
public synchronized boolean add(E e);

4 尺寸和长度,私有变量差异。

ArrayList.size;
Vector.elementCount;

5 其它要领

Vector 比ArrayList要领多,不外一部门是反复的

public synchronized void copyInto(Object[] anArray);
public synchronized void setSize(int newSize);
public synchronized int capacity();
public Enumeration<E> elements();
public synchronized E elementAt(int index);
public synchronized E firstElement();
public synchronized E lastElement();
public synchronized void setElementAt(E obj, int index) ;
public synchronized void removeElementAt(int index);
public synchronized void insertElementAt(E obj, int index);
public synchronized void addElement(E obj);
public synchronized boolean removeElement(Object obj);
public synchronized void removeAllElements();

原文地点:http://www.java2000.net/p9750

 

    关键字:

天才代写-代写联系方式