Array&Linkedlist (1).pdf - 1 What Is an Array 2 Arrays Hold Multiple Values • Array variable that can store multiple values of the same type •

Array&Linkedlist (1).pdf - 1 What Is an Array 2 Arrays...

This preview shows page 1 - 10 out of 36 pages.

2 1- What Is an Array?
Image of page 1

Subscribe to view the full document.

3 Arrays Hold Multiple Values Array : variable that can store multiple values of the same type Values are stored in adjacent memory locations Declared using [] operator 1- datatype[] arrayRefVar; Example: double[] myList; OR 2- datatype arrayRefVar[]; // This style is allowed Example: double myList[];
Image of page 2
4 Array Storage in Memory The definition int [ ] tests; tests = new int[SIZE]; // SIZE is 5 allocates the following memory first element second element third element fourth element fifth element
Image of page 3

Subscribe to view the full document.

5 Array Terminology In the definition int [ ] tests; tests = new int[ISIZE]; int is the data type of the array elements tests is the name of the array ISIZE , in [ISIZE] , is the size declarator. It shows the number of elements in the array. The size of an array is the number of bytes allocated for it (number of elements) * (bytes needed for each element)
Image of page 4
6 Array Terminology Examples The Length of an Array Once an array is created, its size is fixed. It cannot be changed. You can find its size using arrayRefVar.length For example, myList.length returns 10
Image of page 5

Subscribe to view the full document.