Introduction to List and Constructing ArrayList Objects
Have you ever made a list? kept a budget? used a spreadsheet? These are collections of related items we call a list. One way that we can represent this in a program is by using a List, specifically an ArrayList.
An ArrayList is a resizable list, meaning it shrinks and grows as needed.
How Data is Stored?
Each value stored in an ArrayList is called an element. As elements are added to the ArrayList the size of the ArrayList increases by 1.
Similar to the characters in a String, each element in an ArrayList has an index. The first index is 0 and the last is the size of the ArrayList - 1.
Constructing an ArrayList
When constructing an ArrayList object, we must specify the type of data that is stored. An ArrayList only stores reference data. Wrapper classes will be used to store any primitive data.
ArrayList< <type of reference data> > name = new ArrayList<> ();
An example of an ArrayList of student names in a class would be as follows:
ArrayList <String> studentList = new ArrayList<>();
An example of an ArrayList of a student's grades would be as follows:
ArrayList <Integer> studentGrades = new ArrayList<>();
Complete List of ArrayList Tutorials
Resources