Wednesday, November 17, 2010

The different between vector and arrayList in Java

In Java, vector and arrayList are very easy to be confused. Both arrayList and vector are dynamic array. what are they different?
1.vector is synchronized. Therefore, it is safe to use in multithread programs. On the other hand,arrayList is not synchronized, it need to call a function to synchronize. Therefore, it is faster than vector.
2.Vector is build on old framework, it does not need to indicate a type of this vector, for example:
Vector v = new Vector();
arrayList, on the other hand, need to indicate the type of this array.
ArrayList myArr = new ArrayList();

Vector and arrayList in C# is very similar to Java. However,vector in C++ is more like arrayList, not vector in Java.

No comments:

Post a Comment