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)