Unit 6 - Array Flashcards

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

Array

A

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

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

Element

A

single value in an array

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

Index of an element

A

position of element in an array

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

1st element has an index of

A

0

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

Length of array

A

number of elements in an array

is a public final data member of an array

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

Last element of an array is at index

A

list.length-1

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

When an array of ints is created with keyword new, each element is initialized to

A

0

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

Accessing an index that doesn’t exist causes an

A

ArrayIndexOutOfBoundsException

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

Elements of a reference type are initialized to

A

reference value null

Objects are not automatically created

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

Elements of a double type are initialized to

A

0.0

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

Elements of a boolean type are initialized to

A

false

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

Initializer list

A

Used to put values into an array during initialization

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

Initialize an array of type boolean with 4 elements

A

boolean [ ] listOne = new boolean [4]

data type [ ] name = keyword new data type [number of elements]

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

Initializer lists structure

A

data type [ ] name = { parameters separated by commas }

Example
double [ ] grades = {70.5, 88.2, 93.7, 98.7}

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

Use of array objects allows multiple related items to be represented using

A

a single variable

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

Square brackets are used to

A

access and modify an element in a 1D array using an index

17
Q

Valid index values

A

0 to list.length-1

18
Q

How to retrieve a value at index x from an array

A

name [index x]

19
Q

Traversing

A

Access each element of an array

Can be done by iteration statements

20
Q

A for loop can also be

A

used to access some of elements

Be sure to check LCV initialization, conditions, and increment

21
Q

When using loops to access array elements, we need to be careful to prevent an

A

ArrayIndexOutOfBoundsException

22
Q

Enhanced for loops

A

Also known as a for-each loop

Only two components separated by a colon

23
Q

What two components are in the parameter list of an enhanced for loop

A

first component -> type & name of variable that is a copy of value stored in structure

second component -> data structure being traversed with the loop

24
Q

Enhanced for loops are able to

A

access the value stored in variable

25
Q

Enhanced for loops are unable to

A

Assign into the variable defined in header

Don’t have access to indices of array or subscript notation

26
Q

Structure of enhanced for loop

A
for (type declaration : structure)
{ 
      // statement one;
      //statement two;
      // ...
}
27
Q

Algorithm to identify a max/min in an array

A

Method -> local variable needed to store current max/min values being compared to all values in array and assign value to be opposite extreme or first item
Loop -> standard or enhanced both work
-> compare current value against a local variable
currentValue is better, assign to temporary variable

28
Q

Algorithm to calculate average value from objects in an array

A

Method -> local double variable is needed to store accumulated values
for loop -> traverse the array and add current total to variable
After accumulation need to divide total by number of items stored in array

29
Q

Algorithm to shift array contents to the right

A

Make an empty array of the same size
Iterate over original array & properly copy values to adjusted index in new array
Assign new array back into original variable
Only use a standard for loop

30
Q

Algorithm to shift array contents to the left

A

Shift using same array/ go to left with use of nested for loops
Outer loop -> execute # of times we shift
Inner loop -> copy value stored in first index then move all contents one spot left
Copy temp. variable back to end of array