The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
![]() |
Home ![]() ![]() |
||
See also: Arrays and Objects, The Vector Class, Tables | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||
Arrays, Vectors and Tables
Arrays are a generally useful data structure, but they suffer from two important limitations:
In Section 17.10 we saw how the built-in Vector class solves the first problem. As the user adds items it expands automatically. It is also possible to shrink a Vector so that the capacity is the same as the current size. But Vectors don't help with the second problem. The indices are still integers. That's where the Table ADT comes in. The Table is a generalization of the Vector that can use any type as an index. These generalized indices are called keys. Just as you would use an index to access a value in an array, you use a key to access a value in a Table. So each key is associated with a value, which is why Tables are sometimes called associative arrays. A common example of a table is a dictionary, which is a table that associates words (the keys) with their definitions (the values). Because of this example Tables are also sometimes called Dictionaries. Also, the association of a particular key with a particular value is called an entry.
|
||
Home ![]() ![]() |