Deck 7: Arrays and the Arraylist Class
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
العب
ملء الشاشة (f)
Deck 7: Arrays and the Arraylist Class
1
A ragged array is
A) a two-dimensional array where the rows have different numbers 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
A) a two-dimensional array where the rows have different numbers 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
A
2
The String[ ] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
True
3
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
True
4
In order to do a binary search on an array
A) the array must first be sorted
B) you must first do a sequential search to be sure the element you are looking for is there
C) the values of the array must be numeric
D) All of these are true
A) the array must first be sorted
B) you must first do a sequential search to be sure the element you are looking for is there
C) the values of the array must be numeric
D) All of these are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
Objects in an array are accessed with subscripts, just like any other data type in an array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
An ArrayList object automatically expands in size to accommodate the items stored in it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
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 time 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, normally, have the number of comparisons that is half the number of elements in the array
A) is less efficient than the sequential search algorithm
B) will cut the portion of the array being searched in half each time 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, normally, have the number of comparisons that is half the number of elements in the array
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
A(n) __________ is used as an index to pinpoint a specific element within an array.
A) boolean value
B) element
C) range
D) subscript
A) boolean value
B) element
C) range
D) subscript
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
The Java compiler will display an error message when it processes a statement that uses an invalid subscript.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Java does not limit the number of dimensions an array may have.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
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
12
A sorting algorithm is used to locate a specific item in a larger collection of data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
A partially filled array is normally used
A) when only a very small number of values need to be stored
B) when you know how many elements will be in the array but not what the values are
C) with an accompanying parallel array
D) with an accompanying integer value that holds the number of items stored in the array
A) when only a very small number of values need to be stored
B) when you know how many elements will be in the array but not what the values are
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
14
Java provides a mechanism known as a __________ which makes it possible to write a method that takes a variable number of arguments.
A) variable-length argument list
B) dynamic parameter list
C) unary-signature template
D) polymorphic byte code
A) variable-length argument list
B) dynamic parameter list
C) unary-signature template
D) polymorphic byte code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
When an array of objects is declared but not initialized, the array values are set to 0.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
When an array is passed to a method
A) it is passed just as any other object would be passed
B) the method has direct access to the original array
C) a reference to the array is passed
D) All of these are true
A) it is passed just as any other object would be passed
B) the method has direct access to the original array
C) a reference to the array is passed
D) All of these are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
An array of String objects
A) is arranged the same as an array of primitive objects
B) is compressed to four bytes for each element
C) must be initialized when the array is declared
D) consists of an array of references to String objects
A) is arranged the same as an array of primitive objects
B) is compressed to four 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
18
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 collection of data
D) is rarely used with arrays
A) arranges elements in ascending order
B) arranges elements in descending order
C) is used to locate a specific item in a collection of data
D) is rarely used with arrays
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
The sequential search algorithm
A) returns 1 if the value being searched for is found or -1 if the value is not found
B) requires the array to be ascending order
C) uses a loop to sequentially step through an array, starting with the first element
D) All of these are true
A) returns 1 if the value being searched for is found or -1 if the value is not found
B) requires the array to be ascending order
C) uses a loop to sequentially step through an array, starting with the first element
D) All of these are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
To determine if two arrays are equal you must compare each of the elements of the two arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
You can use the __________ method to replace an item at a specific location in an ArrayList.
A) set
B) remove
C) replace
D) add
A) set
B) remove
C) replace
D) add
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
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) 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
23
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 to a String array.
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 to a String array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
Which of the following methods returns a string representing all of the items stored in an ArrayList object?
A) show
B) toString
C) print
D) getList
A) show
B) toString
C) print
D) getList
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
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
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
26
Which method is used to determine the number of items stored in an ArrayList object?
A) items
B) listLength
C) size
D) volume
A) items
B) listLength
C) size
D) volume
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
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.
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
28
What would be the result after the following code is executed?
int[ ] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 1; i < numbers.length; i++)
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.
int[ ] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 1; i < numbers.length; i++)
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
29
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?
A) set
B) store
C) add
D) insert
A) set
B) store
C) add
D) insert
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
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"
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
31
Which of the following import statements is required in order 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;
A) import java.util.Tools;
B) import java.util.ArrayList;
C) import java.util.Containers;
D) import java.util.API;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
What does the following statement do?
double[ ] array1 = new double[10];
A) It declares array1 to be a reference to an array of double values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten double values.
D) It does all of these.
double[ ] array1 = new double[10];
A) It declares array1 to be a reference to an array of double values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten double values.
D) It does all of these.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
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];
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
34
What would 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.
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
35
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]
A) numbers.length
B) numbers.length[r]
C) numbers[r].length
D) numbers[r].length[r]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
What would be the result after the following code is executed?
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.
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
37
To return an array of long values from a method, which return type should be used for the method?
A) long[ARRAY_SIZE]
B) array
C) long[]
D) long
A) long[ARRAY_SIZE]
B) array
C) long[]
D) long
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
The __________ method removes an item from an ArrayList at a specific index.
A) remove
B) pop
C) deleteAt
D) clear
A) remove
B) pop
C) deleteAt
D) clear
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10;
Long[] array1 = new long[ARRAY_SIZE];
A) It declares array1 to be a reference to an array of long values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten long values.
D) All of these are true.
Long[] array1 = new long[ARRAY_SIZE];
A) It declares array1 to be a reference to an array of long values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten long values.
D) All of these are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
What will be the result after the following code is executed?
final int ARRAY_SIZE = 5;
Float[ ] x = float[ARRAY_SIZE];
For (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.
final int ARRAY_SIZE = 5;
Float[ ] x = float[ARRAY_SIZE];
For (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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck