bcis 3630 chapter 7
Bounds Checking
-Occurs at runtime -if invalid subscripts, program throws exception and terminates
Passing an array as an argument to a method
-pass the value in the variable that references an array -when a single elements is passed, it is handled like any other argument
You cannot use the enhanced for loop when..
-you need to change the contents of array element -you need to work through elements in reverse -if you're not accessing all of the elements -if you need to work with two or more arrays -if you need to refer to the subscript number of a certain element
1. numbers[0] = 20 2. numbers[3] = 30
1. numbers sub zero is assigned 20 2. numbers sub 3 is assigned 30
int[ ] numbers = {3,6,9} for (int val : numbers) System.out.println(val);
3 6 9
Individual elements are processed like any other type of variable
True
Methods may return arrays and accept as arguments
True
Once an array is created, it cannot be changed
True
You cannot change the value of an array's length field
True
1. In an array declaration, this indicates the number of elements that the array will have a) subscript b) size declarator c) element sum d) reference variable
b
the first subscript in an array is always a) 1 b) 0 c) -1 d) 1 less than the number of elements
b
this search algorithm steps through an array comparing each item with the search value a) binary search b) sequential search c) selection search d) iterative search
b
Array
can hold multiple values of the same dat type simultaniously
the last subscript in an array is always a) 100 b) 0 c) -1 d) 1 less than the number of elements
d
this is the typical number of comparisons performed by the sequential search on an array of N elements a) 2N b) N c) Nsquared d) N/2
d
String Arrays
each string must be created individually if the array is uninitialized
T/F an array's size declarator can be a negative integer expression
false
T/F 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 rows
false
Reference Copy
int [ ] array1 = { 2,4,6]; int [] array2 = array2 -only the address of the array is copied, not the contents of the array object -after execution, both array variables will reference the same array
enhanced for loop
iterates once for every element in an array
Size Declarator
the number inside the brackets ex: numbers = new int[6]
T/F Java does no allow a statement to use a subscript that is outside the range of valid subscripts for an array
true
T/F a two-dimensional array has multiple length fields
true
T/F an arraylist automatically expands in size to accommodate the items stored in it
true
T/F both of the following declarations are legal and equivalent int[] numbers; in numbers[];
true
T/F the java compiler does not display an error message when it processes a statement that uses an invalid subscript
true
T/F the subscript of the last element in a single-dimensional array is one less than the total number of elements in the array
true
T/F the values in an initialization list are stored in the array in the order that they appear in the list
true
T/F when an array is passed to a method, the method has access to the original array
true
Subscript
used as an index to pinpoint a specific element within an array i.e. 6 elements, subscripts 0-5 ex: numbers[0] pronounced "numbers sub zero"
Partially filled arrays passed as an argument to a method
variable that holds the count of items must also be passed. If not, method would not be able to determine number of items stored
By default, Java initializes array elements as..
Zero
each element of an array is accessed by a number known as a a) subscript b) size declarator c) address d) specifier
a
this search algorithm repeatedly divides the portion of an array being searched in half a) binary search b) sequential search c) selection search d) iterative search
a
to delete an item from an ArrayList object, you use this method a)remove b)delete c)erase d)get
a
to determine the number of items stored in an ArrayList object, you use this method a)size b) capacity c) items d) length
a
when initializing a two-dimensional array, you enclose each row's initialization list in a) braces b) parenthesis c) brackets d) quotation marks
a
array bounds checking happens when the program is a) compiled b) saved c) run d) loaded into memory
c
this array field holds the number of elements that the array has a) size b) elements c) length d) width
c
to insert an item at a specific location in an ArrayList object, you use this method a) store b) insert c) add d) get
c