Java Reference
In-Depth Information
CHAPTER
9
Collections
A collection is an object that represents a group of objects. In this chapter, we
will discuss the various types of collections in Java. I will begin with a discus-
sion on arrays, including how to declare, instantiate, and access arrays. Then,
I will discuss the Java Collections Framework , which is the term used to denote
the various classes and interfaces in the J2SE that represent collections. Collec-
tions discussed in this chapter include vectors, hash tables, maps, and sets.
Arrays
An array is a collection of elements stored in a contiguous block of memory.
Each element in an array must be the same data type, and they are distin-
guished by an index. The first element in the array is at index 0.
Creating an array involves two steps, as follows:
1.
Declaring a reference for the array.
2.
Instantiating the array using the new keyword and specifying the size
of the array.
253
Search WWH ::




Custom Search