ArrayList, Vector

xiaoxiao2021-03-06  37

ArrayList:

1.Arraylist

The method is not synchronized, so it is unsafe in multi-thread, you must sync yourself, and

ArrayList

Many methods declare for multi-threaded operations

There is no provision, that is, the results are unpredictable.

How to synchronize ArrayList and HashMap can be used with collections.synchronizedlist list list = collections.synchronizedlist (new arraylist (...)); collections.synchronizedmap 2.toarray ()

The method returned is the same object as the original list, that is,

: Arraylist.toarray () [0] == arraylist.get (0)

Returned

True

assumed

ArrayList

Unhappy

)

.

3.clone ()

The method is a shallow copy.

4.

Can be called by yourself

EnsureCapacity ()

Improve efficiency. Vector methods are synchronized, is thread-safe, and ArrayList is not, because the synchronization of threads inevitably affect performance, so ARRAYLIST performance is better than Vector. When the element in Vector or ArrayList exceeds its initial size, Vector doubles its capacity, and ArrayList only increases the size of 50%, so ArrayList is conducive to saving memory space. The same is the object collection, and the ArrayList can check by the compiler and the vector is not, so if you return to the object with a vector, the compiler is unable to check, and can only be found when running.

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

New Post(0)