3 - List - ArrayList
3 - List - ArrayList
1
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
2
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
=> ArrayList :-
ArrayList is an implemented class of List
interface which is present in java.util package
Syntax : public class ArrayList extends
AbstractList implements List, RandomAccess,
Cloneable, Serializable
The underline Data-Structure of ArrayList is
resizable array or growable array
ArrayList was introduced in JDK 1.2 version
Properties of ArrayList :-
1. ArrayList is an index based Data Structure
which means that first element will be inserted
at 0 index position
2. ArrayList can store different data types
elements or hetrogeneous elements
3. We can store duplicate elements in the
ArrayList
4. We can store any number of null values in the
ArrayList
3
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
4
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
Working of an ArrayList :-
1. When we create default ArrayList, a new
ArrayList with initial capacity 10 is created (but
size is 0)
2. When the ArrayList capacity is full, a new
ArrayList will be created with new capacity.
The new Capacity is calculated by this formula:-
a. (CurrentCapacity * 3 / 2) + 1
3. Then all the elements will be copied into the
new ArrayList (and due this this reason
performance of an ArrayList decreases)
4. When new ArrayList is created automatically,
then reference variable will point to the new
ArrayList
5. Then old ArrayList object will be not referenced
by any reference and then garbage collection
will delete that object
5
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
Contructors of ArrayList :-
1. ArrayList al=new ArrayList();
a. = In this arraylist, an ArrayList collection
object is created whose capacity is 10
2. ArrayList al=new ArrayList(int initialCapacity);
a. = In this arraylist, an ArrayList object is
created with provided initialCapacity
3. ArrayList al=new ArrayList(Collection c);
a. = In this arraylist, another collection object is
copied into new arraylist object
6
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
7
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
8
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308
Websites: https://www.smartprogramming.in/
https://courses.smartprogramming.in
Android App:
https://play.google.com/store/apps/details?id=com.sma
rtprogramming
YouTube Channel:
https://www.youtube.com/c/SmartProgramming