Wednesday 7 December 2016

Advantages Of Using ArrayList Over Arrays

Array and ArrayList are most used data types while developing any java applications. Both are used to store group of objects. 

In this post I have tried to list down the advantages of using ArrayList over Arrays. Before discussing the advantages of ArrayList, let’s see what are the drawbacks of arrays.

Following Advantages:
  1. An array is type specific i.e. one array can only store data of only one data type where as arraylist can store multiple data in the form of objects. So multiple objects of different data types can be stored in arraylist.
  2. In array you cannot increase or decrease the size dynamically where as in arraylist the size can be increased or decreased dynamically
  3. You can make arraylist readonly.
  4. You can insert element at any location in arraylist
  5. Arraylist supports BinarySearch
  6. ArrayLists implement iterable , which means you can easily iterate them.
  7. If an arraylist is modifed by another thread while it is being iterated by one thread , then it fails fast , which means you don't end up with unreliable data in the list.
  8. An array can be of any data type and contain one data type while array list can contain any data type in the form of the object.

No comments:

Post a Comment