Arrays, Array iteration and the for-each loop Flashcards

1
Q

What is the correct syntax for instantiating an array in Java using an array literal?

A

int[] myArray = {1,2,3}

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

What error is thrown if an attempt is made to access an item at a position beyond the final index of an Array in Java?

A

ArrayIndexOutOfBoundsException

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

True or False?

Once instantiated, Java Arrays have a fixed size.

A

True

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

Given the following code, what would the value of the variable ‘vowel’ be?

char[] vowels = {‘a’,’e’,’i’,’o’,’u’};
char vowel = vowels[2];

A

i

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

What is the property of a Java Array that gives the number of items in the array?

A

length

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

Given an array named myArray, consider this syntax:

myArray[2]

Which of the following statements is true?

A. The syntax could be used, as part of a complete line of code, to retrieve an item in the array.

B. The syntax could be used, as part of a complete line of code, to set the value of an item in the array.

A

Both

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

Given the code below, what is the highest index that could be used to access an item in the array?

String[] words = new String[9];

A

8

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

What is a correct example of a valid ‘for each’ loop, given an array named bookArray?

A
for (String bookTitle: bookArray) {
    //do something
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False?

A Java ‘for each’ loop provides access to the index value of each item in the array as it is iterating.

A

False

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