Java Chapter7

24 July 2022
4.7 (114 reviews)
45 test answers

Unlock all answers in this set

Unlock answers (41)
question
In memory, an array of String objects:
answer
consists of elements, each of which is a reference to a String object
question
The binary search algorithm:
answer
will cut the portion of the array being searched in half each time the loop fails to locate the search value
question
What do you call the number that is used as an index to pinpoint a specific element within an array?
answer
subscript
question
This ArrayList class method is used to insert an item into an ArrayList.
answer
add
question
It is common practice to use a ________ variable as a size declarator.
answer
final
question
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:
answer
str[0].toUpperCase();
question
If numbers is a two-dimensional array, which of the following would give the length of row r?
answer
numbers[r].length
question
When an array is passed to a method:
answer
All of these answers.
question
You use this method to determine the number of items stored in an ArrayList object.
answer
numberItems
question
You can use this ArrayList class method to replace an item at a specific location in an ArrayList.
answer
set
question
The ArrayList class is in this package.
answer
java.util
question
When an individual element of an array is passed to a method:
answer
the method does not have direct access to the original array
question
In Java, you do not use the new operator when you use a(n):
answer
initialization list
question
What do you normally use with a partially-filled array?
answer
An accompanying integer value that holds the number of items stored in the array
question
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
answer
public static void passArray(int [][])
question
In order to do a binary search on an array:
answer
the array must first be sorted in ascending order
question
This ArrayList class method deletes an item from an ArrayList.
answer
remove
question
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.
answer
array bounds checking
question
Each array in Java has a public field named ________ that contains the number of elements in the array.
answer
length
question
Which of the following is a valid declaration for a ragged array?
answer
int[][] ragged = new int[5][];
question
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;
answer
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
question
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; }
answer
180
question
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;
answer
a=5
question
To return an array of long values from a method, use this as the return type for the method.
answer
long[]
question
Declaring an array reference variable does not create an array. T or F?
answer
T
question
To compare the contents of two arrays, you must compare the elements of the two arrays. T or F?
answer
T
question
Objects in an array are accessed with subscripts, just like any other data type in an array. T or F?
answer
T
question
Java does not limit the number of dimensions that an array may have. T or F?
answer
T
question
Once an array is created, its size cannot be changed. True T or F?
answer
T
question
When an array of objects is declared, but not initialized, the array values are set to null. T or F?
answer
T
question
An ArrayList object automatically expands in size to accommodate the items stored in it .T or F?
answer
T
question
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.T or F?
answer
T
question
If a[] and b[] are two integer arrays, the expression a == b compares the array contents.T or F?
answer
F
question
A sorting algorithm is used to locate a specific item in a larger collection of data. T or F?
answer
F
question
Java limits the number of dimensions that an array may have to 15. T or F?
answer
F
question
The sequential search algorithm:
answer
uses a loop to sequentially step through an array, starting with the first element
question
A ragged array is:
answer
a two-dimensional array where the rows are of different lengths
question
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[]?
answer
0 through 14
question
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]; }
answer
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
question
The following statement creates an ArrayList object. What is the purpose of the notation? ArrayList arr = new ArrayList();
answer
It specifies that only String objects may be stored in the ArrayList object.
question
This indicates the number of elements, or values, the array can hold.
answer
the array's size declarator
question
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} };
answer
94
question
Which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];
answer
All the answers are correct
question
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
answer
A reference to the String "ghi"
question
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; }
answer
60