java chapter7
Subscript numbering always starts at what value?
0
What do you normally use with a partially-filled array?
An accompanying integer value that holds the number of items stored in the array
Declaring an array reference variable does not create an array. T or F?
T
Once an array is created, its size cannot be changed. True T or F?
T
What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }
180
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
A reference to the String "ghi"
When an array is passed to a method:
All of these answers.
This ArrayList class method deletes an item from an ArrayList.
remove
Java does not limit the number of dimensions that an array may have. T or F?
T
Objects in an array are accessed with subscripts, just like any other data type in an array. T or F?
T
To compare the contents of two arrays, you must compare the elements of the two arrays. T or F?
T
In order to do a binary search on an array:
the array must first be sorted in ascending order
In Java, you do not use the new operator when you use a(n):
initialization list
Which of the following is a valid declaration for a ragged array?
int[][] ragged = new int[5][];
Each array in Java has a public field named ________ that contains the number of elements in the array.
length
To return an array of long values from a method, use this as the return type for the method.
long[]
If numbers is a two-dimensional array, which of the following would give the length of row r?
numbers[r].length
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passArray(int [][])
You can use this ArrayList class method to replace an item at a specific location in an ArrayList.
set
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:
str[0].toUpperCase();
What do you call the number that is used as an index to pinpoint a specific element within an array?
subscript
This indicates the number of elements, or values, the array can hold.
the array's size declarator
When an individual element of an array is passed to a method:
the method does not have direct access to the original array
The sequential search algorithm:
uses a loop to sequentially step through an array, starting with the first element
What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
The binary search algorithm:
will cut the portion of the array being searched in half each time the loop fails to locate the search value
By default, Java initializes array elements with what value?
0
A sorting algorithm is used to locate a specific item in a larger collection of data. T or F?
F
If a[] and b[] are two integer arrays, the expression a == b compares the array contents.T or F?
F
Java limits the number of dimensions that an array may have to 15. T or F?
F
The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>();
It specifies that only String objects may be stored in the ArrayList object.
This ArrayList class method is used to insert an item into an ArrayList.
add
An ArrayList object automatically expands in size to accommodate the items stored in it .T or F?
T
Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.
array bounds checking
A ragged array is:
a two-dimensional array where the rows are of different lengths
In memory, an array of String objects:
consists of elements, each of which is a reference to a String object
Which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];
All the answers are correct
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.T or F?
T
When an array of objects is declared, but not initialized, the array values are set to null. T or F?
T
It is common practice to use a ________ variable as a size declarator.
final
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?
0 through 14
What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };
94
The ArrayList class is in this package.
java.util
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }
60
What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;
a=5
You use this method to determine the number of items stored in an ArrayList object.
numberItems