Arrays Flashcards

1
Q

What is an array?

A

A named set of contiguous memory cells, a data structure.

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

Array elements are indexed starting at __

A

0

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

Are arrays homogenous or heterogenous?

A

Homogenous, all elements must be of the same data type.

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

What are the square brackets called? “[ ]”

A

Array Index Operator

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

What keyword is used when creating and instantiating an array?

A

new

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

What is meant by “arrays are immutable”?

A

Cannot change the number of elements after instantiation.

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

What is the index number of the last element of an array?

A

length - 1

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

What is the default value for elements of an array?

A

Zero, false, null

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

How do you ensure to never get an “out of bounds” exception?

A

array.length

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

What does Math.random() return?

A

0.000 - 0.99999, NOT 1.0

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

The general formula for Math.random()

A

(int)Math.random() * (highValue - lowValue + 1) + lowValue);

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

Random Access

A

Takes the same amount of time to access any element of the data structure.

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

Why do we start indexing arrays at 0?

A

The offset calculation for the memory address.

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

Offset calculation

A

OFFSET = (datatype in bits) * element index number

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

In which ways is an ArrayList different from an array?

A

1) Heterogenous (different data types)

2) Dynamic (able to add more elements as you go)

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

What is stored in an ArrayList?

A

Object References (memory addresses of objects)

17
Q

How do you specify the object type you wish to hold in an ArrayList?

A

Parameterizing,

18
Q

How do you find the number of filled elements in an ArrayList?

A

.size()

19
Q

Traversing a Collection Object

A

Visiting each and every value in the collection during traversal.

20
Q

What is one good way to traverse an ArrayList?

A

Enhanced for loop (for:each)

21
Q

What is a 2D array?

A

An array of arrays.

22
Q

Which is the rows and which is the columns?

A

int[R][C]

23
Q

How do you fill a 2D array?

A

Nested for loop

24
Q

In a 2D array, when filling the array the outer loop references

A

Rows

25
Q

In a 2D array, when filling the array the inner loop references

A

Columns

26
Q

What is a 2D array with inconsistent column lengths called?

A

A jagged or ragged array