Home
Flashcards
Preview
powerpoint 6.txt
Home
Get App
Take Quiz
Create
What is an array?
An array is a collection of variables of the same type (primitive or class type).
What is a good usage for an array?
To store a list of values - all of the same type.
How do you declare an array?
type[] name = new type[size];
type could be int, double, String, etc.
Once an array is created, its size is _________.
fixed
How do you reference the ith element of an array int numbers = new int[20];
numbers[i]
What is the index of the first position in an array?
0
How can you find the length of an array?
arrayName.length()
What formula will always give you the last index position in an array?
lastPosition = arrayName.length - 1
How could you get the value at the last position in any array?
arrayName[arrayName.length - 1]
How could you get the value at the first position in any array?
arrayName[0]
What is the syntax for initializing an array with a list of values?
int[] arrayName = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
How could you create an array with 16 elements that starts with 1 and each position holds a value that is the last value + 1?
int[] numbers = new int [16];
for (int i=0; i<17; i++)
numbers[i] = i+1;
Review example slides p.8-9.
Should array names be singular or plural?
singular
Name three basic things you can do with arrays.
Assign an individual value to one place
Read an individual value from one place
Read the length of the array
Can you assign values to multiple places in an array at once?
No
Can you perform a numeric operation (like addition or multiplication) on an array?
No
Is this how you compare two arrays: if (a[] == b[]) ...?
No. You first compare the length then each element in the array.
Also, you can use the .equals method.
Can you assign the values of one array to another array like this: a[] = b[];?
no
Author
dimeng
ID
299155
Card Set
powerpoint 6.txt
Description
diane cs140 powerpoint 6
Updated
2015-03-25T14:46:15Z
Show Answers
Home
Flashcards
Preview