Use arraylist instead of Vector

xiaoxiao2021-03-06  51

Many people don't know ArrayList, but they will definitely know the vector, because the vector is more early than ArrayList, so it is used. However, in the Collection framework after Java1.2, Vector has been eliminated, because it is to be kept compatible, this class will always exist, but it is not recommended to be used, this is the compatibility of software, now thinking about many people. It can only be run on IE6.0, it is really angry. For those who are not familiar with Vector, I use arraylist to use ArrayList, but I am used to using the product, it is also possible to turn to ArrayList (although the Vector may always exist in JDK), but we have no reason to give up ArrayList uses the Vector.

Public Class Vector Extends AbstractList Implements List, Randomaccess, Cloneable, Java.io.Serializable It can be seen that the declaration of ArrayList is the same, here does not consider its implementation, to see the main difference: 1.Vector has a method without arraylist : Addelement, Copyinto, Elementat, Elements, FirstElement, FirstElement, etc., here is not listed here, basically excessive methods, and enumeration is also used.

2. Vector's implementation relative to ArrayList is slightly complicated, and the Vector function is not strong than ArrayList, and the code quantity is indeed twice.

Most of the methods in the 3.Vector are synchronous methods, don't think this is its advantages! Synchronization is to pay the price, or many people want to use Double-Check Lock in single case mode (although not feasible). Because the method is synchronized, the efficiency naturally decreases much.

转载请注明原文地址:https://www.9cbs.com/read-115676.html

New Post(0)