Arrays Flashcards
formula for reference for arrays
[ ] =
two ways to create an array
create and list the elements
create sufficient space`
how to create space eg. int array, name numbers, with 5 elements
int [] numbers = new int [5];
can you mix types in a list
no
how to find the number of elements in an array
.length
when an array is empty its called
a null array
what happens if we refer to an index that is outside of the array
ArrayIndexOutOfBoundsException
values of the indexes of an array
from 0 to array.length-1
if you change the contents of one array with multiple references does the array change for all the refernces
yes
ways to make a cpoy of an array
using a for loop to cpoy over each element
arraycopy function
copyOf function
clone function
layout for arraycopy
(source array, starting at element, destination array, starting at element, how many elements are being copied over
layout for copyOf
(copy from, length to be copied)
is the size of an array fixed
yes
to extend or shrink an array we musr
create a new array with our desired length and then copy over elements into that array
do we need to delete arrays if were no longer referencing them
no, java sends them to garbage automatically