Home » Core Java » ArrayList in Java

ArrayList in Java

ArrayList & its feature ::
1.  ArrayList class is an important class of Collection framework.
2.  ArrayList extends generic AbstractList.
3.  ArrayList implements generic List, RandomAccess, Cloneable and java.io.Serializable
4.  ArrayList internally stores elements in a re-sizable array.The default capacity of array is 10 and it grows dynamically by 50% of its default capacity ,if number of element exceeds from its capacity.
5.  ArrayList is roughly equivalent to Vector class except that it is unsynchronized i.e. it is not thread safe.But, it can be made synchronized explicitly like below

5.  ArrayList can accept any element including multiple null values.
7.  ArrayList uses Iterator interface to traverse the elements.While traversing the elements using iterator if the      structure of the ArrayList is modified using add or remove method ,iterator will throw ConcurrentModificationException.So iterators for ArrayList are fail-fast.

Sample Program ::

Output ::

Now let us see an example of ConcurrentModificationException.In the below program while iterating the ArrayList,i am modifying the structure of the ArrayList by adding a new element.So I am getting ConcurrentModificationException.
Example of ConcurrentModificationException ::

Output ::


Leave a comment

Your email address will not be published. Required fields are marked *

two + ten =