Lec 8: Arrays Flashcards

1
Q

Syntax for declaring an array

A

datatype[] arrayRefVar;

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

Syntax for declaring an array of a specific size

A

dataType[] arrayRefVar = new dataType[arraySize];

ex: double[] myList = new double[10];

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

Syntax for getting the length of an array

A

array.length

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

What is the default value of a bool if not preset

A

false

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

what is the default value of a char if not preset

A

‘\u0000’

it is an invisible character

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

syntax for creating an array with specific double elements

A

double[] myList = new double[4]
myList[0] = 1.9;
myList[1] = 2.1;

or
double[] myList = {1.9, 2.9, 3.4, 3.5};

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

What is the syntax for a foreach loop that prints all the elements in an array of double values

A

for (double value : myList){
System.out.println(value);
}

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

Does list 2 = list 1 create a new list?

A

No, it only copied the reference to list 2

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

How to copy the elements of an array to another

A

you must copy the array’s individual elements to the other array

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

When passing an array to a method, what is passed to the method?

A

the reference of the array

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

What is the name of an array without an explicit reference variable?

A

anonymous array

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

True or false” For a parameter of a primitive type, the actual value is passed instead of a reference

A

True

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

True or false: Changing the value of the local parameter inside the method changes the value of the variable outside the method

A

false

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

True or false: for a parameter of an array type, the reference value is passed

A

True

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

True or false: Any changes to the array that occur inside the method body does not affect the original array that was passed as the arg

A

False

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

What is a heap

A

a region of memory used for dynamic memory allocation, where all Java objects are stored when they are created with the new keyword

The java virtual machine stores, for example a new array, inside the heap

17
Q

What defines a ragged array?

A

An array with different row lengths

18
Q

True or false: int a[] = new int[2]; is correct

A

True

19
Q

True or false: int a = new int[2]; is correct

A

False

20
Q

True or false: int[] a = new int(2); is correct

A

False

21
Q

True or false: int[] a = new int[2]; is correct

A

True

22
Q

What is the correct term for numbers[99]?

A

indexed variable

23
Q

Define indexed variable

A

Any variable that is accessed through the index of an array

24
Q

What method copies the sourceArray to the targetArray?

A

System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

25
Q

When you pass an array to a method, the method receives_

A

the reference of the array

26
Q

The JVM stores an array in an area called _ , which used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order

A

Heap

27
Q

When you return an array from a method, the method returns _

A

the reference of the array

28
Q

The _ method sorts the array scores of the double[] type

A

java.util.Arrays.sort(scores);

29
Q

int[] scores = {1, 20, 30, 40, 50}, what does java.util.Arrays.toString(scores) return?

A

[1,20,30,40,50]

30
Q

True or false: the first element of matrix is = 0

int [] [] matrix = new int[5][5];

A

True