6.1 Array Creation and Access
Enduring Understanding
To manage large amounts of data or complex relationships in data, programmers write code that groups the data together into a single data structure without creating individual variables for each value.
Learning Objective
Represent collections of related primitive or object reference data using one- dimensional (1D) array objects.
Essential Knowledge
The use of array objects allows multiple related items to be represented using a single variable.
The size of an array is established at the time of creation and cannot be changed.
Arrays can store either primitive data or object reference data.
When an array is created using the keyword new, all of its elements are initialized with a specific value based on the type of elements:
Elements of type int are initialized to 0
Elements of type double are initialized to 0.0
Elements of type boolean are initialized
Elements of a reference type are initialized to the reference value null. No objects are automatically created
Initializer lists can be used to create and initialize arrays.
Square brackets ([ ]) are used to access and modify an element in a 1D array using an index.
The valid index values for an array are 0 through one less than the number of elements in the array, inclusive. Using an index value outside of this range will result in an ArrayIndexOutOfBoundsException being thrown.
Last updated
Was this helpful?