Arrays Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Two ways to declare and create a one-dimensional array:

A

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}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Once an array is created, its ______ cannot be changed

A

size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The only way to expand an array is:

A

create a bigger array and copy the contents of the original array into the new one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If the limits on an array’s size are too large in a loop:

A

an ArrayIndexOutOfBoundsException is thrown. This is a run-time error, NOT a compile-time error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To declare two dimensional arrays:

A

double[][] matrix = new double[3][5] (3 rows by 5 cols)

int r, c;
matrix[r][c] = 1.23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If m is a two-dimensional array, m.length represents the number of ______ and m[0].length represents the number of _____

A

rows, columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

An array list is defined, with the desired type of its objects “student” as:

A

ArrayList list = new ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

An ArrayList cannot hold values of a ______ data type

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly