Unit 6: Array Flashcards

1
Q

an array is __.

A

a data structure used to implement a collection (list) of primitive or object reference data

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

an element is __.

A

a single value in the array

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

an array’s length ___.

A

cannot be changed after it’s been created

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

initializing an array:

A

dataType [] arrayName = new dataType[element 3]

ex. int [] array = new int[5];

NOTE: there must be a nonnegative integer or 0 in the [ ]

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

when just initializing an array’s num of elements, each element is __.

(name for each of 4 data types)

A

0 for int, 0.0 for double, false for boolean, null for String

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

how to set array element to value:

A

array[index] = value

ex. array[0] = 5;

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

how to initialize array with object elements:

how to set object values:

A

className [] arrayName; OR
className[] arrayName = new arrayName [num of elements];

arrayName[index] = new className(attribute);

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

how to make array with known values:

A

dataType [] arrayName = {element1, element2, …};

NOTICE curly braces

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

only use [] after array name when___.

A

accessing a certain element, not initializing the entire array

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

for: each loop structure:

A

for( dateType variable: array)
{
}

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

how to print out all elements of an array with for: each loop

A

for (dataType variable: array){
System.out.prtinln(variable);
}

NOTE: variable is a copy of what’s in the array, so don’t need to put index of variable

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