ArrayList:-
- The underlying data structure for array list is re-sizable array or growable array
- Insertion order is preserved
- Duplicate objects are allowed
- Heterogeneous objects are allowed.
- Null insertion is possible
Constructors in ArrayList :-
Array List Al = new ArrayList();
- Creates an empty array list object with default initial capacity “IO”,
- Once Al reaches its max capacity then a new AL object will be created with
New capacity = current capacity * 3/2 + 1
Array List L = new ArrayList(int initial capacity);
- Creates an empty Arraylist object with the specified initial capacity.
Array list l = new Arraylist(collection C);
– Creates an equivalent array list object form the given collection objects i.e., this constructor is for dancing b/w collection objects.
Example:-
import java.util. *; Class ArrayListDemo { Public static void main (String[] args) { ArrayList a = new ArrayList() a.add (“A”); a.add (10); a.add(“A”); a.add (null); System.out.println(a); a.remove(2); System.out.println(a); a.add(“N”); a.add(2, “M”); a.add(“N”); System.out.println(a); } }