Disadvantages of ArrayList in C#
ArrayList, Vector, LinkedList difference and its advantages and disadvantages?Nov 22, 2017·7 min read ArrayList, LinkedList, Vestor these three classes have implemented java.util.List interface, but they have their own different characteristics, mainly as follows: First, the synchronizationArrayList, LinkedList is not synchronized, and Vestor is synchronized. So if you do not require thread safety, you can use ArrayList or LinkedList, you can save the overhead for synchronization. But in the case of multi-threaded, sometimes you have to use Vector. Of course, there are ways to wrap the ArrayList, LinkedList, so that they also achieve synchronization, but the efficiency may be reduced. Second, the growth datafrom the internal implementation mechanism in terms of ArrayList and Vector are using an array of Objec to store. When you add elements to both types, they all need to extend the length of the internal array if the number of elements exceeds the current length of the internal array. By default, Vector automatically grows by twice the size of the original ArrayList. Of the 50%, so in the end you get this collection always occupy more space than you really need. So if you want to save large amounts of data in a collection, there are some advantages to using Vector since you can avoid unnecessary resource overhead by setting the initial size of the collection. Third, the efficiency of the search, insert, delete objectsArrayList and Vector, from the specified location (index) to retrieve an object, or insert at the end of the collection, delete an object is the same time, can be expressed as O (1) . However, if you add or remove an element elsewhere in the collection, the time it takes increases linearly by: O (ni), where n is the number of elements in the collection and i is the indexs position where elements are added or removed. Why is this so? It is assumed that all the elements after the ith and ith elements in the set are to perform (ni) displacement operations on the objects when the above operation is performed. Generally we all know ArrayList and LinkedList roughly the difference :1.ArrayList is based on a dynamic array of data structures, LinkedList data structure based on the list. ArrayList and LinkedList are two collection classes for storing a series of object references. For example, we can use ArrayList to store a series of String or Integer. So ArrayList and LinkedList in performance What is the difference? When should ArrayList use LinkedList? Java code The output I get is: ArrayList Time-consuming: 15 Java code LinkedList Time: 15 two. Space complexity the Java Code a reference list element for each object in the Entry, as well as in the LinkedList Its the previous element and the next element. A LinkedList object of 1000 elements will have 1000 linked Entry objects, each corresponding to an element in the list. In this case, there is a large overhead in a LinkedList structure because it stores information about the 1000 Entity objects. three. Summary 2. Inserting or deleting an element in the middle of an ArrayList means that the remaining elements in the list are all moved; the overhead of inserting or deleting an element in the middle of a LinkedList is fixed. 3. LinkedList does not support efficient random element access. 4. ArrayList space waste is mainly reflected in the end of the list to reserve a certain amount of space, and LinkedList space cost is reflected in each of its elements need to consume considerable space It can be said that using an ArrayList will provide better performance when the operation is to add data to the back of a column of data rather than in front of or in the middle of the column, and you need to randomly access the elements. When your operation is in front of a column of data Or add or delete data in the middle, and in order to access the elements, you should use LinkedList. So, if you just look for elements in a particular location or just add to the end of the collection, remove the elements, then use Vector or ArrayList. If it is inserted into the other designated location, delete operation, the best choice LinkedList |