ArrayLists are a part of the Collection Framework offered by Java as a part of the java.util package. Collections are data structures which can be used to hold a group of objects together as a single entity and perform operations on top. They are also provided with powerful and useful methods and features which can reduce the overall programming effort.
- ArrayList (java.util package) is Dynamic Array (Resizable-array).
- ArrayList implements RandomAccess interface (Marker interface) used for fast random access based on index.
- RandomAccess interface (Marker interface) is used in searching, add, removing object in particular index of ArrayList.
- ArrayList extends AbstractList class which provides implementation to List interface.
Constructors in ArrayList:
- ArrayList(): This is default constructor of Arraylist. It will have initial capacity of size 10.
- ArrayList(Collection c): This constructor will add existing collection object to ArrayList.
- ArrayList(int capacity): This constructor is used to overwrite initial capacity of ArrayList.
true true 22
Features of ArrayList:
- Index based structure – ArrayList is an Index based structure in java.
- Duplicate elements – ArrayList allows to store duplicate elements in java.
- Null elements -Null elements can be added in ArrayList in java.
- Insertion order – ArrayList maintains insertion order in java.
- Asynchronous – It is not synchronized (because 2 threads on same ArrayList object can access it at same time).
- Performance – ArrayList is not synchronized, hence its operations are faster as compared to some other synchronized implementation of List interface in java.