Java Reference
In-Depth Information
ArrayList Method
Corresponding Vector Method
ArrayList()
Vector()
add()
addElement()
get()
elementAt()
set()
setElementAt()
remove()
remove()
size()
size()
K EYED C OLLECTIONS : H ASHTABLE AND H ASH M AP
The most commonly used keyed list is the HashMap or its older cousin, the
Hashtable . Java 1.5 introduces a high-performance implementation of HashMap :
ConcurrentHashMap . All classes support a growable array of objects that can be ac-
cessed with a key.
These classes are used for managing objects and providing direct access to the
objects. Like ArrayList s and Vector s, you can only place objects into them. When
using Generics, the compiler will ensure that the object returned is the type speci-
fied for the collection. If you need to, you can cast the returned object to the cor-
rect type in order to be able to use it.
From a COBOL perspective, maps can be viewed as similar to the indexed file
type. The index of the file is analogous to the keys in a Map collection, and the
record area is analogous to the values in a Map collection. To be more precise, an
indexed sequential (ISAM) file type is very similar to the TreeMap collection, and
an indexed file accessed via a hashed key is very similar to the HashMap collection.
A program can create a Hashtable or HashMap using this syntax:
Hashtable errorMsgsTable = new Hashtable ();
HashMap errorMsgsMap = new HashMap ();
Like Vector and ArrayList , Hashtable and HashMap have constructors that pass
an integer for the capacity of the collection and a size attribute. Also, you should
specify the object types that your collection will contain using the <ObjectType,
ObjectType> qualifier.
 
Search WWH ::




Custom Search