ArrayList vs Vector: Which one to use?

At the very beginning, I admit that I am an idiot; but there is one thing that I just can’t understand. It seems that I do not see much difference between ArrayListand Vector, except for this:

"... (This class is roughly equivalent to Vector, except that it is unsynchronized.) ..."

in javaDocs ArrayList .

So, is this difference really an important factor in applying these two similar classes when we consider a common scenario (i.e. exclude an application in Thread-based programming)? Are there any other distinctive differences? If yes, please tell me. If not, which one is most preferred or generally accepted?

+4
source share
5 answers

In addition to differences with synchronization, an internal difference also occurs when inserting new elements. For both classes, the array inside should be increased in size to prevent its absence from the room. Vectors double their size by default. ArrayLists increase their size by half from their current size.

Edit:

, , . - , , ( ), , , (). . ( ArrayLists), , , ( ).

+4

Java API:

" ArrayList Vector"

Collections:

Collections.synchronizedList(List<T> list)

List list = Collections.synchronizedList(new ArrayList());

() , .

+4

, , , ArrayLists - . , , , - , , , .

ArrayLists , Collection, Collection , ..

, !

+4

, , , , ArrayList ( , List).

, Vector, ArrayList.

0

java 1.0

ArrayList java 1.2

ArrayList.

, :

= Collections.synchronizedList( ArrayList (...));

0

Source: https://habr.com/ru/post/1529213/


All Articles