Advertisement
vladimirVenkov

What is the difference between Array, ArrayList and LinkedLi

Oct 24th, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. What is the difference between Array, ArrayList, and LinkedList in Java?
  2.  
  3. From the hierarchy diagram, they all implement List interface. They are very similar to use. Their main difference is their implementation which causes different performance for different operations.  ArrayList is implemented as a resizable array. As more elements are added to ArrayList, its size is increased dynamically. Its elements can be accessed directly by using the get and set methods since ArrayList is essentially an array. LinkedList is implemented as a double linked list. Its performance on add and remove is better than ArrayList but worse on getting and set methods.
  4.  
  5. Vector is similar to ArrayList, but it is synchronized. ArrayList is a better choice if your program is thread-safe. Vector and ArrayList require space as more elements are added. Vector each time doubles its array size, while ArrayList grow 50% of its size each time. LinkedList, however, also implements Queue interface which adds more methods than ArrayList and Vector, such as offer(), peek(), poll(), etc.    Note: The default initial capacity of an ArrayList is pretty small. It is a good habit to construct the ArrayList with a higher initial capacity. This can avoid the resizing cost.  
  6.  
  7. https://www.javatpoint.com/difference-between-arraylist-and-linkedlist
  8.  
  9. https://dzone.com/articles/arraylist-vs-linkedlist-vs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement