Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
47 Cards in this Set
- Front
- Back
How many values are normal variables designed to hold?
|
Only one, as opposed to arrays, which can hold multiple values.
|
|
How many types can a single array hold?
|
Only one type (but can have many instances of those types)
|
|
Arrays are ______, (the positions are numbered) starting with ____.
|
Indexed 0 |
|
An array can be thought of as a collection, list, or table of ____________.
|
Data Elements
|
|
An array is an _________, so it needs an _______ reference.
|
object
|
|
What would be the declaration of an array that holds 5 integers?
|
int [ ] numbers = new int [5];
|
|
Integer arrays are always initialized to ____
|
0
|
|
We may declare an _____________ and create a __________ in the same statement.
|
array reference New array instance |
|
Arrays may be made of ______ types and _________ types.
|
Value & Reference |
|
The array size must be a _________
|
Positive Integer
|
|
Array sizes can be a __________ value, a ________, or __________.
|
Literal, Constant, Variable
|
|
Using a ____________ is preferred because the array size may be used in many places in the code and this way provides for easy changes
|
Named Constant
|
|
Once an array is created, can its size be altered?
|
No
|
|
In the list: numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5] what does each item represent?
|
The reference names of the array
|
|
An array is accessed by the ___________ and a __________ or ______________ that identifies which element in the array to access.
|
reference name, subscript, index |
|
Array elements ___________________________ as any other variables
|
be used as
|
|
How are array elements accessed?
|
array name & subscript
|
|
If keyboard is your Scanner object and you want to store input into hours[0]. How would you do this?
|
hours[0] = keyboard.nextInt();
|
|
Array __________ always start at ____ and continue through (__________).
|
indexes, zero, (array length - 1) |
|
If an some variable tries to be a reference for an array item that does not exist, what kind of error is thrown? (For example, if you try to put some data into arrayObjects[max + 1])
|
ArrayIndexOutOfBoundsException
|
|
An initialization list can be used to initialize the array when ___________
|
There are relatively few items to be initialized.
|
|
Size of the array is determined by _____________________, not necessarily the _______________that the spaces hold.
|
the number of spaces that exist, value
|
|
Sometimes using an advanced for loop is not preferable, what is a poignant example of this encountered in class?
|
When you need to reference the index (or whatever your counter is) for use in the loop. Such as if you need to use the same index for two or more arrays like Month and date)
|
|
In addition to initializing an array by setting all the values, one may assign an _____________ to the ______________________.
|
existing array object, new array reference
|
|
If Face is an enumerated type listing all faces in a playing card, how could you create an array of Faces named myFaces and initialize it with all the possible faces using the values method which is present in all enumerated types?
|
Face[ ] myFaces = Face.values( );
|
|
ALTERNATE ARRAY DECLARATION: what is an alternate position for the brackets that is different from: int [ ] numbers; ? How about for numbers and codes?
|
int numbers [ ]; | int numbers [ ], int codes[ ]
|
|
How do you declare multiple int (or any type) arrays on the same line? (use numbers, codes, and scores)
|
int [ ] numbers, codes, scores;
|
|
Processing a data item in an array is done the same way as any other variable. Give an example of the fourth item of the hours array being multiplied by the payRate variable and this product being put into grossPay.
|
grossPay = hours[3] * payRate;
|
|
How is the Enhanced for Loop described?
|
Simplified array processing (read only) Loops through all elements. "for each item in the array, do..." |
|
What is Dr. Bailes algorithm for "enhanced for loops"?
|
for (datatype elementVariableName : arrayName) { statement; } (Where the data type should be the same as the data type of the array being used. |
|
Arrays themselves are __________ts and each provides a _______ field named ____________ that is a c__________t that can be tested, displayed, compared, etc.
|
objects, public field, length, constant
|
|
Index subscripts are/ are not equal to index length
|
not, the index goes to 1 - arrayLength
|
|
If you allow the user to specify array size, what should you do to keep things....okay?
|
Run a check to make sure the user specifies a reasonable size
|
|
You can r__________gn array references :) but what happens to the old array values?
|
reassign, they are LOST
|
|
int [ ] array2 = array1 Is this the right or wrong way to copy an array? What is the proper name for this method? |
NOT THE RIGHT WAY! It's called a Shallow Copy
|
|
To correctly copy an array, you must first have ___________ arrays of the _______ _____ze (NOT JUST 2 REFERENCES TO THE SAME ARRAY) Then you must _______ the _________ elements of one array to the other, one ________ at a time. |
two separate, same size, copy the individual elements, one at a time in aloop
|
|
What is the correct method of copying arrays called?
|
A Deep Copy
|
|
Arrays can be _________ed to methods like any other _______________ r______________e variable
|
passed, object reference
|
|
When comparing arrays, the == operator only determines whether array _______________ refer to the _______ a_____ ________t
|
references, same array object
|
|
What are some common tasks for which we have algorithms?
|
-Fill or populate an array with info -Display array -Find largest/smallest value in an array -Determine whether an array contains a particular value -Sort the data in the array into some order |
|
What is the algorithm for finding the largest in an array?
|
- Scan the items one at a time - The first item is the largest at this point - Scan the rest until we find larger - Remember this ^ - Repeat previous 2 steps until finished - At the end we will have the largest item |
|
The difference in code between comparing the smallest items vs the largest items is...
|
Changing the > to an < in the if (arrayName[ I ] targetValue)
|
|
What was the header for accessing arrays?
|
Accessing the Elements of an Array
|
|
When talking about the fact that array elements can be used as any other variable, what was the header?
|
Inputting and Outputting Array Elements
|
|
What (this was a header) is required to ensure that you do not try to access an element that does not exist?
|
Bounds Checking
|
|
When you use a for loop (other examples may exist) and you your loop goes one beyond the array length, what error is this called?
|
off-by-one
|
|
what is the proper term for: int numbers [ ];
|
Array Declaration
|