Explain ArrayList and difference between ArrayList and Vector?
- ArrayList is a class, that uses a dynamic array for storing the elements. It extends AbstractList class and implements List interface.
- The underlying data structure is a Resizable array or growable array.
- Duplicates are allowed.
- Insertion order is preserved.
- Heterogeneous objects are allowed(except TreeSet and TreeMap everywhere Heterogeneous objects are allowed)
- Null insertion is possible.
- Manipulation slows because a lot of shifting needs to occur if any element is removed from the array list.
- Usually, we can use the collection to hold and transfer objects from one location to another location (container) to provide support for this requirement every collection class by default implementsÂ Serialization and Cloneable interface.
- ArrayList and vector classes implementÂ the RandomAccess interfaceÂ so that any random element we can access with the same speed.
- ArrayList is a data structure that can be stretched to accommodate additional elements within itself and shrink back to a smaller size when elements are removed. It is a very important data structure useful in handling the dynamic behavior of elements.
Constructors in ArrayList
|1||ArrayList l=new ArrayList()||
|2||ArrayList l=new ArrayList(int initial capacity)||
|3||ArrayList l=new ArrayList(Collection c)||