Implements the List interface.
Dynamic 1D array of objects of the same type.
The 1st element has the 0th index.
Differences between ArrayList and LinkedList:
ArrayList implements List, LinkedList implements List, Queue and Deque
ArrayList stores a simple value, LinkedList stores the element, previous and next addresses
ArrayList provides a resizeable array, LinkedList provides a doubly-linked list
For inserting element, ArrayList shifts all elements after, LinkedList modifies prev and next fields in the surrounding nodes
To access data, in ArrayList elements can be accessed randomly, in LinkedList sequentially
Differences between Vector and ArrayList:
in case a thread opens the Vector for writing, the Vector will be blocked for other threads, for them throws an exception (ArrayList is safe for multi-tread access)
ArrayList uses Collection.synchronizedList() to synchronize accessing methods (Vector blocks instead)
Based upon these, usage of ArrayList is preferred for thread-safety, and it is more efficient.
EXAMPLE FOR MAKING SYNCHRONIZED (THREAD-SAFE) ARRAYLIST:
In case a Collection is passed to the particular method, throws an exception if the Collection is null or not compatible.
In case an index is passed to the method, throws an exception if the index is out of bounds.
EXAMPLE FOR ARRAYLIST METHODS:
EXAMPLE FOR LAMBDA IN ARRAYLIST:
EXAMPLE FOR LAMBDAS:
EXAMPLE FOR ITERATOR IN ARRAYLIST:
The ListIterator class would have the same processing structure however it can move backward as well and can replace the last read element.
EXAMPLE FOR SORTING IN ARRAYLIST:
Without declaring a Comparator, uses basic comparing technics.
By declaring a Comparator, custom and complex comparing technics can be introduced.
EXAMPLE FOR BASIC COMPARING TECHNICS:
EXAMPLE FOR ARRAYLIST-ARRAY CONVERSION:
EXAMPLE FOR ARRAYLIST-MAP CONVERSION:
EXAMPLE FOR CREATING AND FILLING AN ARRAYLIST: