Arrays Flashcards
Two ways to declare and create a one-dimensional array:
SomeType[] a = new SomeType[size]
SomeType[] b = {value0, value1, value2, value3, …, value(n-1) }
EXAMPLES:
double[] samples = new double[100]
int[] numbers = {1, 2, 3}
Once an array is created, its ______ cannot be changed
size
The only way to expand an array is:
create a bigger array and copy the contents of the original array into the new one.
If the limits on an array’s size are too large in a loop:
an ArrayIndexOutOfBoundsException is thrown. This is a run-time error, NOT a compile-time error.
To declare two dimensional arrays:
double[][] matrix = new double[3][5] (3 rows by 5 cols)
int r, c;
matrix[r][c] = 1.23
If m is a two-dimensional array, m.length represents the number of ______ and m[0].length represents the number of _____
rows, columns
An array list is defined, with the desired type of its objects “student” as:
ArrayList list = new ArrayList
An ArrayList cannot hold values of a ______ data type
primitive. for example, the object is not allowed to be String, int, or double, but ints and doubles can be added to an ArrayList or ArrayList respectively, due to auto boxing