Deck 7: Arrays and the ArrayList Class

ملء الشاشة (f)
exit full mode
سؤال
When an array is passed to a method

A) it is passed just as any other object would be.
B) the method has direct access to the original array.
C) a reference to the array is passed.
D) All of the above
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
The following import statement is required to use the ArrayList class:

A) import java.util.Tools;
B) import java.util.ArrayList;
C) import java.util.Containers;
D) import java.util.API;
سؤال
What will be the result of the following code?
Final int ARRAY_SIZE = 5;
Float[] x = float[ARRAY_SIZE];
For(int i = 1; i <= ARRAY_SIZE; i++)
{
X[i] = 10.0;
}

A) A runtime error will occur.
B) All the values in the array will be initialized to 10.0.
C) All the values in the array, except the first, will be set to 10.0.
D) The code contains a syntax error and will not compile.
سؤال
What will be the result of executing the following code?
Int[] x = {0, 1, 2, 3, 4, 5};

A) An array of 6 values, all initialized to 0 and referenced by the variable x, will be created.
B) An array of 6 values, ranging from 0 through 5 and referenced by the variable x, will be created.
C) The variable x will contain the values 0 through 5.
D) A compiler error will occur.
سؤال
For the following code, what would be the value of str[2]?
String[] str = {"abc", "def", "ghi", "jkl"};

A) a reference to the String object containing "ghi"
B) "ghi"
C) a reference to the String object containing "def"
D) "def"
سؤال
A partially filled array is normally used

A) when a very small number of values need to be stored.
B) when you know how many elements will be in the array.
C) with an accompanying parallel array.
D) with an accompanying integer value that holds the number of items stored in the array.
سؤال
The ________ method removes an item from an ArrayList at a specific index.

A) remove
B) pop
C) deleteAt
D) clear
سؤال
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

A) numbers.length
B) numbers.length[r]
C) numbers[r].length
D) numbers[r].length[r]
سؤال
What will be the result of the following code?
Int[] numbers = {40, 3, 5, 7, 8, 12, 10};
Int value = numbers[0];
For (int i = 1; i < numbers.length; i++)
{
If (numbers[i] < value)
Value = numbers[i];
}

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
سؤال
Given the following two-dimensional array declaration, which statement is true?
Int[][] numbers = new int[6][9];

A) The numbers array has 54 rows.
B) The numbers array has 15 rows.
C) The numbers array has 6 rows and 9 columns.
D) The numbers array has 6 columns and 9 rows.
سؤال
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} };

A) 95
B) 84
C) 94
D) 93
سؤال
What will be the result of the following code?
Int[] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 0; i < numbers.length; i++)
Value += numbers[i];

A) The value variable will contain the sum of all the values in the numbers array.
B) The value variable will contain the highest value in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the average of all the values in the numbers array.
سؤال
Which of the following is a valid declaration for a ragged array with five rows, but no columns?

A) int[][] ragged = new int[5];
B) int[][] ragged = new int[][5];
C) int[][] ragged = new int[5][];
D) int[] ragged = new int[5];
سؤال
What is a ragged array?

A) a two-dimensional array where the rows have a different number of columns
B) a one-dimensional array for which the number of elements is unknown
C) a two-dimensional array for which the number of rows is unknown
D) a partially initialized two-dimensional array of ranged values
سؤال
You use this method to determine the number of items stored in an ArrayList object.

A) items
B) listLength
C) size
D) volume
سؤال
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

A) set
B) store
C) add
D) insert
سؤال
You can use the ________ method to replace an item at a specific location in an ArrayList.

A) set
B) remove
C) replace
D) add
سؤال
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passMyArray(int[]myArray1, int[]myArray2)
B) public static void passMyArray(int[][] myArray)
C) public static void passMyArray(int myArray)
D) public static void passMyArray(array myArray)
سؤال
A search algorithm

A) arranges elements in ascending order.
B) arranges elements in descending order.
C) is used to locate a specific item in a larger collection of data.
D) is rarely used with arrays.
سؤال
This method returns a string representing all of the items stored in an ArrayList object.

A) show
B) toString
C) print
D) getList
سؤال
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
سؤال
An ArrayList object automatically expands in size to accommodate the items stored in it.
سؤال
To return an array of long values from a method, use this as the return type for the method.

A) long[ARRAY_SIZE]
B) array
C) long[]
D) long
سؤال
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
سؤال
Which of the statements are true about the following code?
Final int ARRAY_SIZE = 10;
Long[] array1 = new long[ARRAY_SIZE];

A) declares array1 to be a reference to an array of long values
B) creates an instance of an array of 10 long values
C) will allow valid subscripts in the range of 0 through 9
D) All of the above
سؤال
A sorting algorithm is used to locate a specific item in a larger collection of data.
سؤال
The sequential search algorithm

A) returns 1 if the value being search for is found, otherwise it returns -1.
B) requires the array to be in ascending ordered.
C) uses a loop to sequentially step through an array, starting with the first element.
D) All of the above
سؤال
A(n) ________ is used as an index to pinpoint a specific element within an array.

A) element
B) range
C) boolean value
D) subscript
سؤال
Java provides a mechanism known as ________, which makes it possible to write a method that takes a variable number of arguments.

A) variable-length argument lists
B) dynamic parameter lists
C) unary-signature templates
D) polymorphic byte codes
سؤال
Java does not limit the number of dimensions that an array may have.
سؤال
To determine if two arrays are equal, you must compare each of the elements of the two arrays.
سؤال
What does the following statement do?
Double[] array1 = new double[10];

A) declares array1 to be a reference to an array of double values
B) will allow valid subscripts in the range of 0 through 9
C) creates an instance of an array of 10 double values
D) All of the above
سؤال
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command line.
سؤال
Objects in an array are accessed with subscripts, just like any other data type in an array.
سؤال
In order to do a binary search on an array,

A) the array must first be sorted in ascending order.
B) you must first do a sequential search of the array to assure the element you are looking for is there.
C) the values of the array must be numeric.
D) All of the above
سؤال
When an array of objects is declared, but not initialized, the array values are set to 0.
سؤال
What does specify in the following statement?
ArrayList nameList = new ArrayList();

A) It specifies that String objects may not be stored in the ArrayList object.
B) It specifies that everything stored in the ArrayList object will be converted to a String object.
C) It specifies that only String objects may be stored in the ArrayList object.
D) It specifies that the ArrayList will be converted into a String array.
سؤال
The binary search algorithm

A) is less efficient than the sequential search algorithm.
B) will cut the portion of the array being searched in half each it fails to locate the search value.
C) will have a maximum number of comparisons equal to the number of elements in the array.
D) will have an average number of comparisons that is half the number of elements in the array.
سؤال
The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.
سؤال
An array of String objects

A) is arranged the same as an array of primitive objects.
B) is compressed to 4 bytes for each element.
C) must be initialized when the array is declared.
D) consists of an array of references to String objects.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 7: Arrays and the ArrayList Class
1
When an array is passed to a method

A) it is passed just as any other object would be.
B) the method has direct access to the original array.
C) a reference to the array is passed.
D) All of the above
D
2
The following import statement is required to use the ArrayList class:

A) import java.util.Tools;
B) import java.util.ArrayList;
C) import java.util.Containers;
D) import java.util.API;
B
3
What will be the result of the following code?
Final int ARRAY_SIZE = 5;
Float[] x = float[ARRAY_SIZE];
For(int i = 1; i <= ARRAY_SIZE; i++)
{
X[i] = 10.0;
}

A) A runtime error will occur.
B) All the values in the array will be initialized to 10.0.
C) All the values in the array, except the first, will be set to 10.0.
D) The code contains a syntax error and will not compile.
D
4
What will be the result of executing the following code?
Int[] x = {0, 1, 2, 3, 4, 5};

A) An array of 6 values, all initialized to 0 and referenced by the variable x, will be created.
B) An array of 6 values, ranging from 0 through 5 and referenced by the variable x, will be created.
C) The variable x will contain the values 0 through 5.
D) A compiler error will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
For the following code, what would be the value of str[2]?
String[] str = {"abc", "def", "ghi", "jkl"};

A) a reference to the String object containing "ghi"
B) "ghi"
C) a reference to the String object containing "def"
D) "def"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
A partially filled array is normally used

A) when a very small number of values need to be stored.
B) when you know how many elements will be in the array.
C) with an accompanying parallel array.
D) with an accompanying integer value that holds the number of items stored in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
The ________ method removes an item from an ArrayList at a specific index.

A) remove
B) pop
C) deleteAt
D) clear
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

A) numbers.length
B) numbers.length[r]
C) numbers[r].length
D) numbers[r].length[r]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
What will be the result of the following code?
Int[] numbers = {40, 3, 5, 7, 8, 12, 10};
Int value = numbers[0];
For (int i = 1; i < numbers.length; i++)
{
If (numbers[i] < value)
Value = numbers[i];
}

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Given the following two-dimensional array declaration, which statement is true?
Int[][] numbers = new int[6][9];

A) The numbers array has 54 rows.
B) The numbers array has 15 rows.
C) The numbers array has 6 rows and 9 columns.
D) The numbers array has 6 columns and 9 rows.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
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} };

A) 95
B) 84
C) 94
D) 93
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
What will be the result of the following code?
Int[] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 0; i < numbers.length; i++)
Value += numbers[i];

A) The value variable will contain the sum of all the values in the numbers array.
B) The value variable will contain the highest value in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the average of all the values in the numbers array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following is a valid declaration for a ragged array with five rows, but no columns?

A) int[][] ragged = new int[5];
B) int[][] ragged = new int[][5];
C) int[][] ragged = new int[5][];
D) int[] ragged = new int[5];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
What is a ragged array?

A) a two-dimensional array where the rows have a different number of columns
B) a one-dimensional array for which the number of elements is unknown
C) a two-dimensional array for which the number of rows is unknown
D) a partially initialized two-dimensional array of ranged values
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
You use this method to determine the number of items stored in an ArrayList object.

A) items
B) listLength
C) size
D) volume
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

A) set
B) store
C) add
D) insert
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
You can use the ________ method to replace an item at a specific location in an ArrayList.

A) set
B) remove
C) replace
D) add
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passMyArray(int[]myArray1, int[]myArray2)
B) public static void passMyArray(int[][] myArray)
C) public static void passMyArray(int myArray)
D) public static void passMyArray(array myArray)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
A search algorithm

A) arranges elements in ascending order.
B) arranges elements in descending order.
C) is used to locate a specific item in a larger collection of data.
D) is rarely used with arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
This method returns a string representing all of the items stored in an ArrayList object.

A) show
B) toString
C) print
D) getList
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
An ArrayList object automatically expands in size to accommodate the items stored in it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
To return an array of long values from a method, use this as the return type for the method.

A) long[ARRAY_SIZE]
B) array
C) long[]
D) long
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the statements are true about the following code?
Final int ARRAY_SIZE = 10;
Long[] array1 = new long[ARRAY_SIZE];

A) declares array1 to be a reference to an array of long values
B) creates an instance of an array of 10 long values
C) will allow valid subscripts in the range of 0 through 9
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
A sorting algorithm is used to locate a specific item in a larger collection of data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
The sequential search algorithm

A) returns 1 if the value being search for is found, otherwise it returns -1.
B) requires the array to be in ascending ordered.
C) uses a loop to sequentially step through an array, starting with the first element.
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
A(n) ________ is used as an index to pinpoint a specific element within an array.

A) element
B) range
C) boolean value
D) subscript
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Java provides a mechanism known as ________, which makes it possible to write a method that takes a variable number of arguments.

A) variable-length argument lists
B) dynamic parameter lists
C) unary-signature templates
D) polymorphic byte codes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
Java does not limit the number of dimensions that an array may have.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
To determine if two arrays are equal, you must compare each of the elements of the two arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
What does the following statement do?
Double[] array1 = new double[10];

A) declares array1 to be a reference to an array of double values
B) will allow valid subscripts in the range of 0 through 9
C) creates an instance of an array of 10 double values
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command line.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
Objects in an array are accessed with subscripts, just like any other data type in an array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
In order to do a binary search on an array,

A) the array must first be sorted in ascending order.
B) you must first do a sequential search of the array to assure the element you are looking for is there.
C) the values of the array must be numeric.
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
When an array of objects is declared, but not initialized, the array values are set to 0.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
What does specify in the following statement?
ArrayList nameList = new ArrayList();

A) It specifies that String objects may not be stored in the ArrayList object.
B) It specifies that everything stored in the ArrayList object will be converted to a String object.
C) It specifies that only String objects may be stored in the ArrayList object.
D) It specifies that the ArrayList will be converted into a String array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
The binary search algorithm

A) is less efficient than the sequential search algorithm.
B) will cut the portion of the array being searched in half each it fails to locate the search value.
C) will have a maximum number of comparisons equal to the number of elements in the array.
D) will have an average number of comparisons that is half the number of elements in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
An array of String objects

A) is arranged the same as an array of primitive objects.
B) is compressed to 4 bytes for each element.
C) must be initialized when the array is declared.
D) consists of an array of references to String objects.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.