
Using Arrays and Collections
The data types described in previous lessons each hold a single piece of data. A variable might
hold an integer, string, or point in time.
Sometimes it’s convenient to work with a group of related values all at once. For example, sup-
pose you’re the CEO of a huge company that just posted huge losses. In that case, you might want
to give each hourly employee a 10 percent pay cut and give each executive a 15 percent bonus.
In cases like this, it would be handy to be able to store all of the hourly employee data in one
variable so you could easily work with it. Similarly you might like to store the executives’ data
in a second variable so it’s easy to manage.
In this lesson, you learn how to make variables that can hold more than one piece of data. You
learn how to make arrays and different kinds of collections such as
Lists, Dictionaries,
Stacks, and Queues.
This lesson explains how to build these objects and add and remove items from them.
Lesson 19 explains how to get the full benefit of them by looping through them to perform
some action on each of the items they contain.
ARRAYS
An array is a group of values that all have the same data type and that all share the same name.
Your code uses an index, which is an integer greater than or equal to 0, to pick a particular item
in the array.
An array is similar to the mailboxes in an apartment building. The bui