# Outline of Class 16: Experimenting with Vectors and Dictionaries

Held: Friday, February 13, 1998

• Assignment three is now ready and is due next Friday.
• Assignment four is also ready and is due the following Tuesday.
• We'll spend most of today's class on lab 7.
• For Monday, read section 9.1 of Bailey.

## Dictionaries

• In our investigation of vectors, we've seen a structure that collects objects in which the objects can be indexed by numbers.
• Are there other ways to index collections? Yes, we could index collections by "any object".
• Collections of objects indexed by objects (e.g., strings) are called dictionaries.
• Why do we do we want dictionaries? They make many tasks more convenient.
• Keeping track of objects we've seen (if an object is an index in the dictionary, we've seen it; if it's not an index in the dictionary, we haven't seen it).
• Counting things (associate a counter with each object; when you see another copy, increment the counter).
• How do we do build dictionaries? Right now, we'll just use dictionaries and won't worry about how they work. Later, we'll look at how to build them.
• Some terminology:
• The objects we're using as indices are called keys.
• The objects we're looking up are called values.
• What features do we need in a dictionary? Some are similar to those we need for Vectors.
• Add something to the dictionary (requires a key and value).
• Look up something in the dictionary (requires a key, returns a value).
• Remove something from the dictionary.
• Others correspond more to the different structure of dictionaries.
• List all the keys in the dictionary.
• List all the values in the dictionary.

### Hash Tables

• Hash tables are one mechanism for implementing dictionaries. They provide an implementation in which it is likely, but not guaranteed, that access to particular elements will be quick.
• In Java, `java.util.Hashtable` implements the interface `java.util.Dictionary`.
• Well ... `Dictionary` isn't really an interface; it's an abstract class. Nonetheless, it's similar enough for our purposes.
• For now, you can think of hash tables as equivalent to dictionaries. When you need a dictionary, create a hash table.

On to Comparable Objects
Back to Vectors and Dictionaries
Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
Current position in syllabus

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.