Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. The fundamental differences between Array and ArrayList are the same as those between Array and Vector. Both ArrayList and Vector are generic wrapper classes containing a private array instance, whose methods to add or remove elements of the private array will increase or decrease respectively the size of the array (and therefore the memory it requires). This is done by checking when adding or removing items whether the array is of the appropriate size given the number of elements it contains, create a new array of an appropriate size, copying each element to the new array, and updating its private array property to reference the new array. They also allow the user to preemptively grow or shrink the array as a performance optimization if the user can anticipate how many elements will be added, or if there are no more elements to add.
  2.  
  3. The primary practical difference between Vectors and ArrayLists is in their use in multithreaded programs. Vectors are “synchronized”, meaning that their mutating methods are all implemented with the “synchronized” keyword, and so are guaranteed to work in multithreaded programs without errors. The synchronized keyword does cause a performance penalty, so if the built-in synchronized methods are unnecessary for the program being written, the program may run slower than with an ArrayList used in place of a Vector. A program using ArrayList may still make use of the synchronized keyword.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement