powerpoint 6.txt

  1. What is an array?
    An array is a collection of variables of the same type (primitive or class type).
  2. What is a good usage for an array?
    To store a list of values - all of the same type.
  3. How do you declare an array?
    • type[] name = new type[size];
    • type could be int, double, String, etc.
  4. Once an array is created, its size is _________.
  5. How do you reference the ith element of an array int numbers = new int[20];
  6. What is the index of the first position in an array?
  7. How can you find the length of an array?
  8. What formula will always give you the last index position in an array?
    lastPosition = arrayName.length - 1
  9. How could you get the value at the last position in any array?
    arrayName[arrayName.length - 1]
  10. How could you get the value at the first position in any array?
  11. 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};
  12. 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;
  13. Review example slides p.8-9.
  14. Should array names be singular or plural?
  15. 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
  16. Can you assign values to multiple places in an array at once?
  17. Can you perform a numeric operation (like addition or multiplication) on an array?
  18. 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.
  19. Can you assign the values of one array to another array like this: a[] = b[];?
Card Set
powerpoint 6.txt
diane cs140 powerpoint 6