Hour 9. Storing Information with Arrays

What You’ll Learn in This Hour:

• Creating an array

• Setting the size of an array

• Giving a value to an array element

• Changing the information in an array

• Making multidimensional arrays

• Sorting an array

No one benefited more from the development of the computer than Santa Claus. For centuries, humankind has put an immense burden on him to gather and process information. Old St. Nick has to keep track of the following things:

• Naughty children

• Nice children

• Gift requests

• Homes with impassable chimneys

• Women who want more from Santa than Mrs. Claus is willing to let him give

• Countries that shoot unidentified aircraft first and ask questions later

Computers were a great boon to the North Pole. They are ideal for the storage, categorization, and study of information.

The most basic way that information is stored in a computer program is by putting it into a variable. The list of naughty children is an example of a collection of similar information. To keep track of a list of this kind, you can use arrays.

Arrays are groups of related variables that share the same type. Any type of information that can be stored as a variable can become the items stored in an array. Arrays can be used to keep track of more sophisticated types of information than a single variable, but they are almost as easy to create and manipulate as variables.


Note

Java is flexible about where the square brackets are placed when an array is being created. You can put them after the variable name instead of the variable type, as in the following:

String niceChild[];

To make arrays easier for humans to spot in your programs, you should stick to one style rather than switching back and forth. Examples in this book always place the brackets after the variable or class type.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.130.45