Chapter 7 Arrays (Review)
Unlike an array, an ArrayList ArrayList allows object:
-Automatically expands when a new item is added -Automatically shrinks when items are removed
A binary search:
-requires an array sorted in ascending order. -starts with the element in the middle of the array. - If that element is the desired value, the search is over. -Otherwise, the value in the middle element is either greater or less than the desired value -If it is greater than the desired value, search in the first half of the array. - Otherwise, search the last half of the array. - Repeat as needed while adjusting start and end points of the search.
The sequential search algorithm uses a loop to:
-sequentially step through an array - compare each element with the search value - and stop when the value is found or the end of the array is encountered.
3. The first subscript in an array is always ___________.
0
4. The last subscript in an array is always __________.
1 less than the number of elements
The default capacity of an ArrayList is _______ items
10
15. True or False: An array's sitze declarator can be a negative integer expression
False
21. True or False: The first size declarator in the declaration of a two-dimensional array represents the number of columns. The second size declarator represents the number of row
False
What is the difference between a size declarator and a subscript?
The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element in an array.
14. True or False: Java does not allow a statement to use a subscript that is outside the range of valid subscripts for an array.
True
16. True or False: Both of the following declarations are legal and equivalent: int[] numbers; int numbers[];
True
17. True or False: The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array
True
18. True or False: The values in an initialization list are stored in the array in the order that they appear in the list
True
19. True or False: The Java compiler does not display an error message when it processes a statement that uses an invalid subscript
True
20. True or False: When an array is passed to a method, the method has access to the original array.
True
22. True or False: A two-dimensional array has multiple length fields.
True
23. True or False: An ArrayList automatically expands in size to accommodate the items stored in it
True
The ArraList class's ___ method with one argurment adds new items to the end of the ArrayList.
add
To insert an item at a specific location in an ArrayList object, you use this method.
add
To populate the ArrayList use the ____ method
add
Assigning one array reference variable to another with the = operator merely copies the _____ in one variable to the other.
address
A search _______ is a method of locating a specific item in a larger collection of data.
algorithm
7. This search algorithm steps through an array, comparing each item with the search value.
b. sequential search
8. This search algorithm repeatedly divides the portion of an array being searched in half.
binary search
10. When initializing a two-dimensional array, you enclose each row's initialization list in ___________.
braces
Initializing a two-dimensional array requires enclosing each row's initialization list in its own set of _____.
braces
Once created, an array size is fixed and _____ be changed.
cannot
You _____ copy an array by merely assigning one reference variable to another. You need to copy the individual elements of one array to another.
cannot
You ______ use the == operator to compare two array reference variables and determine whether the arrays are equal.
cannot
An ArrayList has a _____, which is the number of items it can hold without increasing its size.
capacity
In two-dimensional, each row has a length constant tells how many ____ is in that row. Each row can have a different number of columns.
columns
You can create a ragged array by creating a two arraydimensional array with a specific number of rows, but no _____.
columns
9. This is the typical number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found).
d. N/2
There is no ____ between passing a single or two-dimensional array as an argument to a method. The method must accept a two array as a parameter.
difference
Java ___ _____ limit the number of dimensions that an array may be.
does not
Java___ ____ allow you to use a subscript value that is outside the range of valid subscripts for an array.
does not
Array _____can be treated as any other variable. They are simply accessed by the same name and a subscript.
elements
An array's length is a _____. You do not write a set of parentheses after its name.
field
Arrays have a finalfieldnamed length. String objects have a method named length. To display the length of each string held in a Stringarray:
for (inti= 0; i<names.length; i++) System.out.println(names[i].length());
To access items in an get method use ___ method
get
ArrayList require import :
import java.util.ArrayList ;
Arrays allow us to create a collection of like values that are _____.
indexed
Array ______ always start at zero and continue to array length - 1
indexes
To copy an array, you should copy the ____ ____ of one array to another.
individual elements
The length of an array can be obtained via its _____constant.
length
This array field holds the number of elements that the array has.
length
A String's lengthis a ____. You do write the parentheses after the name of the Stringclass's length method.
method
If an initialization list is not provided, the _____ keyword must be used to create the array
new
An array is an _____ so it needs an object reference.
object
Each element of a String array is a String _______.
object
Arrays are ______. Their references can be passed to methods like any other object reference variable.
objects
When processing the data in a two dimensional array, each element has two subscripts:
one for its row and another for its column.
An array can store any type of data but ____ _____type of data at a time.
only one
To designate a different capacity of the ArrayList, use a ______ constructor
parameterized
When the rows of a two-dimensional array are of different lengths, the array is known as a ___ ____
ragged array
A method can return a _____to an array. The return type of the method must be declared as an array of the right type
reference
The ArrayList class's ______ method removes designated item from the ArrayList
remove
To delete an item from an ArrayList object, you use this method.
remove
When thinking of a two-dimensional array as having rows and columns, the first subscript accesses a _____ and the second subscript accesses a _____. If you reverse these subscripts, you will access the wrong element.
row, column
Two- dimensional arrays are arrays of one-dimensional arrays. The length field of the array gives the number of _____ in the array.
rows
Declaring a two-dimensional array requires two sets of brackets and two size declarators• The first one is for the number of ____ The second one is for the number of ______
rows, columns.
In a ______sort: The smallest value in the array is located and moved to element 0. Then the next smallest value is located and moved to element 1. This process continues until all of the elements have been placed in their proper order.
selection
The ArrayList class's ____ method replace an existing item
set
13. To determine the number of items stored in an ArrayList object, you use this method.
size
The array _____ must be nonnegative number. It may be a literal value, a constant, or variable.
size
To get the size the ArrayList use ____method.
size
1. In an array declaration, this indicates the number of elements that the array will have.
size declarator
2. Each element of an array is accessed by a number known as a(n) __________.
subscript
An element's subscript and the value stored in the element are not the same thing. The ______ identifies an element, which holds a value.
subscript
Array _______can be accessed using variables
subscripts
An array is accessed by:
the reference name a subscript that identifies which element in the array to access.
The ArrayList class's _____method returns a string representing all items in the ArrayList.
toString
To insert items at a location of choice of the ArrayList, use the add method with ____ argurment.
two
A ____ -____array is an array of arrays. It can be thought of as having rows and columns.
two-dimensional
Processing data in an array is the same as any other _____.
variable
When a single element of an array is passed to a method it is handled like any other ________.
variable
Array bounds checking happens __________.
when the program runs
When processing arrays, the subscripts start at _____ and end at ___ ___ than the number of elements in the array. Off-by-one errors are commonly caused when a loop uses an initial subscript of one and/or uses a maximum subscript that is equal to the number of elements in the array.
zero, one less