And the difference between Arraylist of Vector and Linkedlist

     1. First, we analyze from their underlying data structure

          (1) Arraylist can see and Vector are implemented based on an array, you can constitute a word from its structure, but the two still have a little bit of difference

                  Arraylist The principle is to use the default constructor to achieve a dynamic array of objects to create an empty array

           

            

         The principle is the use of Vector's a dynamic array of objects to achieve, but it's the default constructor creates a new array of objects of size 10

          

       

      

     

    (2) Arraylist first additive element, when extended capacity is 10, the expansion algorithm after: + half of the original size of the original array is an array (i.e. 1.5-fold)

      

      

     

     

     

It should be clearly aware of the principles underlying the expansion of the ArrayList. Similar expansion mechanisms and the Vector Arraylist, the difference is the Vector, Vector two cases 0 case if each increment is doubled capacity expansion, that is 2 times the original, and when the incremental> 0 when expanded to its original size incrementing, and ArrayList is 1.5 times. 1.5-fold increase seems very slow, often increase the number of elements that will lead to frequent expansion, array reallocation inefficient it? In actual fact, every increase of 1.5 times the original amount of the actual increase will be larger and larger
   (3) so Arraylist and Vector unsuitable to delete or insert operation

    (4) In order to prevent excessive expansion of dynamic arrays, it is recommended to create ArrayList or Vector time, given the initial capacity.

    (5) Arraylist multithreading unsafe for use, suitable for use in single-threaded access, higher efficiency, and Vector thread-safe, suitable for use in multi-threaded access, less efficient

 

Guess you like

Origin www.cnblogs.com/kyrieblog/p/11128882.html