Arrays Flashcards
What is an array?
A named set of contiguous memory cells, a data structure.
Array elements are indexed starting at __
0
Are arrays homogenous or heterogenous?
Homogenous, all elements must be of the same data type.
What are the square brackets called? “[ ]”
Array Index Operator
What keyword is used when creating and instantiating an array?
new
What is meant by “arrays are immutable”?
Cannot change the number of elements after instantiation.
What is the index number of the last element of an array?
length - 1
What is the default value for elements of an array?
Zero, false, null
How do you ensure to never get an “out of bounds” exception?
array.length
What does Math.random() return?
0.000 - 0.99999, NOT 1.0
The general formula for Math.random()
(int)Math.random() * (highValue - lowValue + 1) + lowValue);
Random Access
Takes the same amount of time to access any element of the data structure.
Why do we start indexing arrays at 0?
The offset calculation for the memory address.
Offset calculation
OFFSET = (datatype in bits) * element index number
In which ways is an ArrayList different from an array?
1) Heterogenous (different data types)
2) Dynamic (able to add more elements as you go)
What is stored in an ArrayList?
Object References (memory addresses of objects)
How do you specify the object type you wish to hold in an ArrayList?
Parameterizing,
How do you find the number of filled elements in an ArrayList?
.size()
Traversing a Collection Object
Visiting each and every value in the collection during traversal.
What is one good way to traverse an ArrayList?
Enhanced for loop (for:each)
What is a 2D array?
An array of arrays.
Which is the rows and which is the columns?
int[R][C]
How do you fill a 2D array?
Nested for loop
In a 2D array, when filling the array the outer loop references
Rows