The bottom layer of java basic collection introduces the default initial capacity, loading factor, and expansion increment of ArrayList, Vector, HashMap, HashTable, and HashSet
Here we will discuss these commonly used default initial capacities and reasons for expansion: When the underlying implementation involves expansion, the container may reallocate a larger continuous memory (if it is discrete allocation, there is no need to reallocate, discrete allocation allocates memory dynamically when inserting new elements), the original memory of the container must be All data is copied to new memory, which undoubtedly greatly reduces efficiency. The coefficient of the loading factor is less than or equal to 1, which means that when the number of elements exceeds the capacity length * the coefficient of the loading factor, the capacity will be expanded. In addition, the expansion also has a default multiple, and the expansion conditions of different containers are different. List Elements are ordered and repeatable The default initial capacity of ArrayList and Vector is 10 Vector: thread safe, but slow The underlying data structure is an array structure The loading factor is 1: that is, when the number of elements exceeds the capacity length, the capacity will be expanded Expansion increment: 1 times the original capacity For example, the capacity of Vector is 10, and after one expansion, the capacity is 20 ArrayList: thread-unsafe, fast…
Java collection framework | ArrayList, Vector, LinkedList (1)
theme: channing-cyan This is the 7th day of my participation in the August article update challenge,View event details:August article update challenge ArrayList, Vector, and LinkedList are three common collection classes – they all implement the List interface (the List interface inherits the Collection interface) – so what are the differences between the three? xff1f; 1. Comparison between ArrayList and Vector Why should we compare ArrayList and V first? ector What’s the difference? The most important thing is that they are both ordered sets. That is, the positions where the elements in these two sets are stored are all ordered. They are different from the array itself. Both are dynamic – when we use both – we can retrieve an element by position index – and both allow the stored data to be repeated. So what is the main difference between the two? In terms of synchronization Vector is thread-safe& #xff0c; The so-called thread safety means that when multiple threads access shared resources, atomicity, visibility, and order can be guaranteed at the same time. The implementation of Vector’s thread safety is to use the synchronized keyword. Regarding the principle of this keyword, I wrote in the article “Don’t panic when meeting…

Comparison and summary of ArrayList, Vector, LinkedList, HashMap, HashTable, and HashSet in Java
1. The parent class of all collections is the Collection interface 2.Set List Map difference A In the Set, the order of elements cannot be added, so the elements in the Set cannot be repeated B In the List, there is an index Number,is similar to an array,the elements in it can be repeated,the order of addition can be remembered C In Map:each item has a key value Pair composition (key, value) 3.iteratorInterface(Iterator,Traverser): This interface is also Java Members of the collection framework,This interface is mainly used for traversal(iterative access)CollectionElements MainlyUse three methods: A boolean hasNext():Returns true if the iterated collection elements have not been traversed yet, B Object next():returns the next element in the collection element,Cursor. The element returned by the next method. 4. Differences in the use of Vector and ArrayList – All in the Vector class The methods are all thread synchronized – it will be safe for multiple…