ArrayLists Flashcards
What is a Class?
A blueprint of an Object that defines the data and behavior of an Object
Give an example of a Class and Object
A blueprint of a house is a Class. The actual house is the Object.
What is the Collection Class?
The framework that allows us to store an manipulate groups of objects.
What is an ArrayList?
A Collection Class Object that allows us to use Objects in an array.
Explain the difference between an Array and an ArrayList.
Arrays are:
- Fixed length
- Hold one type of data
- Are accessed by index number
- Have a predefined number of elements
- May contain primitives or Objects
ArrayLists are:
- Variable in length
- Hold more than one type of data
- Use methods to access the data
- Do not need to have predefined length/size
- Can only contain Objects. No primitives
What is the Object Class?
The class that holds all other Java classes
An ArrayList is a type of:
List
A List is a type of:
Object
Two ways to define an ArrayList:
ArrayList name = new ArrayList(); List name = new ArrayList();
In what order are the elements of an ArrayList stored?
In the order that they were added
What is an import statement?
Imports the predefined package and class that will be used for a type of Object
What needs to be imported to use an ArrayList?
java.util.ArrayList;
What does this code do? ArrayList names = new ArrayList();
Creates a new empty ArrayList of Strings`
How do you add an element to an ArrayList?
array-list-name.add(Object);
Why can’t you add an int, double, boolean, or float to an ArrayList?
ArrayLists cannot hold primitive types.