Tuesday, March 18, 2008

ICA-CP Class Summary: String Arrays

State:
An array is a data structure for storing data of the same type.

Elaborate:
An array is declared by listing the data type followed a set of square brackets, then the name of the array. For example, to create an array of type string called names, we would use this line:

string [] names;

To declare and fill a string array, we would list the contents after declaring the array:

String [] names = ("Huey", "Dewey", "Louie");

Exemplify:
An array is like a set of lockers, each being numbered successively. For example, if we want an array of 8 items, it would be like having a row of lockers numbered 0, 1, 2, 3, 4, 5, 6, and 7. What goes inside is our data. For example, if we have an array with three names: Huey, Dewey, and Louie, the array would have:
1) Huey in locker 0.
2) Dewey in locker 1.
3) Louie in locker 2.

In Java, the array would have
1) Huey in names[0]
2) Dewey in names[1]
3) Louie in names[2]

Illustrate
So, arrays are like rows of lockers. Each row has a unique name. Each locker in a row has a unique number.

0 Comments:

Post a Comment

<< Home