Arrays Flashcards
toString method
displays elements in array as a string saves having to iterate in a loop
what type are arrays
arrays are objects so they are reference types
position of an element is called
index or subscript
What is different about using a for each instead of a for loop
the for each only lets you access the elements, not modify
accessing an array program
a program refers to any of the the elements in the array with an array access expression
where do arrays store length
in a length instance variable. accessed using array.length
default values within arrays
if the element is
primitive - 0
boolean - false
reference - null.
getting the length of a datatype
for arrays - .length this is an instance variable. this is because the length of an array cannot be altered, so it can be stored in a variable
for Strings - .length() this is a method of the string class because the length of a string can change so it must be recalculated if it is modified. BUT remember Strings can be stored inside of arrays