Arrays, Array iteration and the for-each loop Flashcards
What is the correct syntax for instantiating an array in Java using an array literal?
int[] myArray = {1,2,3}
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?
ArrayIndexOutOfBoundsException
True or False?
Once instantiated, Java Arrays have a fixed size.
True
Given the following code, what would the value of the variable ‘vowel’ be?
char[] vowels = {‘a’,’e’,’i’,’o’,’u’};
char vowel = vowels[2];
i
What is the property of a Java Array that gives the number of items in the array?
length
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.
Both
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];
8
What is a correct example of a valid ‘for each’ loop, given an array named bookArray?
for (String bookTitle: bookArray) { //do something }
True or False?
A Java ‘for each’ loop provides access to the index value of each item in the array as it is iterating.
False