Introduction of Array List:
ArrayList is an implementation of List interface. It is dynamically resizable data structure and hence preferred over simple array when size of the array can not be determined in advance. ArrayList can increase or decrease its size dynamically.
ArrayList is not synchronized. If more than one thread try to access elements in List simulataneously and one of the thread modifies the element, JVM throws concurrentmodification exception. Hence, Array List should be synchronized in a multi threaded enviornment.
Vector is also an implementation of List interface but it is synchronized collection.
Similarity between Array and ArrayList:
Both are index based data structure.
Difference between Array and ArrayList:
Size of an Array is fixed and can not be changed at run time while Linked List can expand or shrink at run time.
Complexity Analysis of ArrayList:
1. Adding element at perticular index: This function is completed in amortized time and hence complexity of adding element in ArrayList is O(n).
2. Getting element : Get function is performed in constant time. Hence, complexity of updating element at the head is O(1).
Array List class in JAVA provides following methods:
1. add(int index, Object element)
2. add(Object element)
3. addAll(int index, Collection elements)
4. addAll(Collection elements)
5. contains(Object element)
6. get(int index)
7. indexOf(Object element)
8. remove(int index)
More about ArrayList including time complexity is coming very soon.