Unit 6 - Array Flashcards
Array
Data structure used to implement a collection or list of primitive or object reference data
Element
single value in an array
Index of an element
position of element in an array
1st element has an index of
0
Length of array
number of elements in an array
is a public final data member of an array
Last element of an array is at index
list.length-1
When an array of ints is created with keyword new, each element is initialized to
0
Accessing an index that doesn’t exist causes an
ArrayIndexOutOfBoundsException
Elements of a reference type are initialized to
reference value null
Objects are not automatically created
Elements of a double type are initialized to
0.0
Elements of a boolean type are initialized to
false
Initializer list
Used to put values into an array during initialization
Initialize an array of type boolean with 4 elements
boolean [ ] listOne = new boolean [4]
data type [ ] name = keyword new data type [number of elements]
Initializer lists structure
data type [ ] name = { parameters separated by commas }
Example
double [ ] grades = {70.5, 88.2, 93.7, 98.7}
Use of array objects allows multiple related items to be represented using
a single variable