Vector中的方法是同步的
ArrayList则不然

解决方案 »

  1.   

    java.util 
    Class Vector
    java.lang.Object
      |
      +-java.util.AbstractCollection
            |
            +-java.util.AbstractList
                  |
                  +-java.util.Vectorjava.util 
    Class ArrayList
    java.lang.Object
      |
      +-java.util.AbstractCollection
            |
            +-java.util.AbstractList
                  |
                  +-java.util.ArrayListNote that ArrayList implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:  List list = Collections.synchronizedList(new ArrayList(...));
      

  2.   

    推荐使用ArrayList(两者本质上是相似的)
      

  3.   

    一般如果你写的程序不涉及线程问题的时候就用ArrayList,因为Vector是同步的方法,所以开销大!