java.util.Vector

      First of all, java.util.ArrayList is well known to everyone. It is an array collection, which is characterized by order, repeatability, fast query, and thread insecurity . Although there are many advantages, but often in multi-threaded scenarios, its use method needs to be considered more, and it is necessary to add the lock without hesitation when it is time to lock.

      However, in addition to ArrayList, there is a collection class that is very similar to it, and that is java.util.Vector. Let's talk about their similarities and differences.

 

  Same point

  • are all array structures;
  • All inherit AbstractList and implement List<E>, RandomAccess, Cloneable, java.io.Serializable.

  difference

  • ArrayList is thread-unsafe, Vector is thread-safe. So the efficiency of Vector is much lower than that of ArrayList;
  • Both ArrayList and Vector use linear continuous storage space (array). When the storage space is insufficient, ArrayList defaults to 50% of the original size, and Vector defaults to double the original size;
  • Vector can set capacityIncrement, but ArrayList cannot. Literally, it is the capacity capacity, Increment increases, and the capacity grows parameters.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326271929&siteId=291194637