Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arrays.

Similar presentations


Presentation on theme: "Arrays."— Presentation transcript:

1 Arrays

2 Copy of a Variable Two variables are independent of each other if their values can change independently of each other

3 Copying an Array (1)

4 Copying an Array (2) The array element identified by the name a[0] is the same array element that is identified by the name b[0] The statement b = a; did not make a (true) copy of an array Aliasing = using different names to access the same variable

5 Copying an Array (3)

6 Copying an Array (4) In Java, we can change an existing array reference to make it point to a different set of array elements The Java programming system has a built-in utility that reclaim the memory cells used by inaccessible variables (= garbage)

7 Copying an Array (5) In order to copy an array in Java, we must:
Create another array (of the same size) using the new operator Copy the elements (one by one) from the old array into the new array.

8 Copying an Array (6)

9 Static and dynamic arrays (1)
Static array = an array name that refers to an array where the number of elements in the array is constant (fixed) Dynamic array = an array name that refers to an array where the number of elements in the array can be changed

10 Static and dynamic arrays (2)
We first create a new array of the desired length Then, we must copy the elements from the old array into the newly created array Finally, we make the variable a point to the new array.

11 Static and dynamic arrays (3)

12 Static and dynamic arrays (4)

13 String Array and Command Line Argument

14 Command arguments (1) Command = an application program that is being executed Argument = the words that follow the command

15 Command arguments (2)

16 Command arguments (3)

17 Command arguments (4)

18 Converting String to array of char and vice versa (1)

19 Converting String to array of char and vice versa (2)

20 Converting String to array of char and vice versa (3)

21 Example


Download ppt "Arrays."

Similar presentations


Ads by Google