Professional Documents
Culture Documents
Lab 1 - Arrays
Lab 1 - Arrays
Arrays
• An array is an aggregate data structure that is
designed to store a group of objects of the same
types.
• The array is the most efficient data structure for
storing and accessing a sequence of objects.
• Array: a set of pairs (index and value)
• For each index, there is a value associated with
that index.
• implemented by using consecutive memory.
Arrays
• Arrays are…
• complex variables that can hold multiple values of the same data
type.
• The size declarator indicates…
• the number of elements the array can hold.
• Individual values inside of an array are called…
• elements.
• An element’s index (or subscript) is…
• a uniquely identifying number that is used to pinpoint its position in
the array.
Operations Performed on Array
Arrays
• Java arrays are objects
• must be accessed via handles
• Defining an array
Type [] name
•This declares the handle only
• Where: •Initialized to null
•Stores an address when arrays are created
• Type specifies the kind of values the array stores
• the brackets [ ] indicate this is an array
• name is the handle to access the array
• String[] cars;
Definitions Using Array Literals
• Used when exact size and initial values of an array are
known in advance
• used to initialize the array handle