1. An array is a block of memory that stores a collection of data items (elements) of __________ under one name.
2. You can store a value in an array using an _______ (location in the array).
3. In the following code listing the array is _____.
4. The above code shows an array of _________________. Specifically, those objects are the words that have been typed by the user at program launch.
5. What is happening in this line?
6. In Java, an array is an object. This object has a given type for the contained primitive types or objects (int, char, String, ...)
7. At line 1, we instantiate an array of 10 items that get the default value (which is 1 for int). At lines 2 and 3, we instantiate array with a maximum value of 10.
array1 = new int[10];
int[] array0 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; //this only works in the declaration
array1 = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
TRUE
FALSE
8. Arrays and lists in most programming languages start counting elements from the number 1, so the first element in an array in Java is at index 1.
9. What is the correct declaration for an array of ints? Select from the options below.
10. The declarations actually create the array. Arrays are objects in Java, so any variable that declares an array holds the values in the array directly.
11. If the array has not been created yet and you try to print the value of the variable, it will print _____(meaning it does not reference any object yet).
12. To actually create an array after declaring the variable, use the__________with the type and the size of the array (the number of elements it can hold).
13. The size of an array is set at the time of creation and cannot be changed after that.
14. Which of the following creates an array of 10 doubles called prices?
15. Fill in the blanks for no. 4 below.
16. Another way to create an array is to use an initializer list. You can initialize (set) the values in the array to a list of values in ___________ when you create it, like below
int[ ] highScores = {99,98,98,88,68};
String[ ] names = {"Jamal", "Emily", "Destiny", "Mateo", "Sofia"};
17. Which index is for the last element of an array called highScores?
18. Since the first element in an array is at index 0 the last element is the length ______.
19. Fill in the blank with the code to access the cars array. String v =
20. Using an index value outside of 0 - (length-1) will result in an ArrayIndexOutOfBoundsException being thrown.
21. Which statement best describes what is happening below on line 2.
22. Arrays can store object reference data but never primitive data.
23. The length of a two-dimensional array is the number of one-dimensional arrays it contains.
24. In the following example, weirdTwoDimArray.length is 3, whereas weirdTwoDimArray[2].length is ___.
String[][] weirdTwoDimArray = {{"10", "11", "12"},
null,
{"20", "21", "22", "23", "24"}};
25. What is the output of the code section below?
int nbItems = 10;
Object[] array3 = new Object[nbItems];
System.out.println(array3.length); VIDEO