32b-hashmaps - CS 106A Handout #32b July 29, 2009 The...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Handout #32b CS 106A July 29, 2009 The ArrayList and HashMap Classes Most of the power associated with modern, object-oriented languages like Java does not come from the language itself but instead derives from the vast array of standard library classes that accompanies the language itself. For Java, that set of libraries is called the Java Development Kit, or JDK for short. Today’s focus is on two classes— ArrayList and HashMap —that form part of a much larger structure called the Java Collections Framework, which was added to the JDK as part of release 1.2 (we’re now up to JDK version 1.5). As its name implies, the Java Collections Framework is designed to make it easier for programmers to work with collections of data of various kinds. The ArrayList class is designed to make it easier to work with ordered lists of data without having to take account of the low-level details of arrays. The HashMap class provides the ability to organize a collection, not by a linear order, but rather by setting up an association between a set of keys and a corresponding set of values. Given any class in a toolkit like the JDK, it is possible to understand that class from a variety of perspectives. From a holistic perspective, each class is defined in terms by its abstract behavior. In this view, the important information about a class consists of the public methods it exports and a high-level model of what those methods do. From a reductionistic perspective, on the other hand, a class is defined in terms of its underlying implementation. At this level, the important information lies in the actual code for the methods it contains. If you are creating a class, you need to be concerned about each of these perspectives. In the more likely case that you are using a class as a tool, you can limit yourself to the more holistic, abstract view. In programming parlance, code that makes use of a class—and by extension the programmers who write that code—are called clients of that class. As a general rule, clients can remain blissfully ignorant of the implementation of a class and concentrate solely on the abstraction it presents to the outside world. In CS 106A, our primary concern is to learn how to use classes as clients. In CS 106B, you will have a chance to look more deeply into how these classes are implemented and how you can use some very clever algorithms to make them as efficient as possible. The ArrayList class I introduced the ArrayList class briefly during the discussion of data files earlier in the quarter. A more detailed description of the class appears in the text, which means that there is not much that this handout needs to add to the discussion. The most important methods for the ArrayList class appear in Figure 10-4. What I want to focus on in
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/14/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 5

32b-hashmaps - CS 106A Handout #32b July 29, 2009 The...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online