Collection Classes in the Java API


So far in this chapter we have been discussing only how to create and manipulate arrays, but the java.util package of the Java API contains a variety of collection classes that you can use in your scientific or engineering applications. One difference between the java.util collection classes and arrays is that the java.util collection classes can store only objects. They cannot be used to store primitive types. This section is intended to give a snapshot of the collection classes available in the java.util package. For complete details on these classes, including the constructors and methods available to them, consult the Sun Java API documentation.

Here are some of the important collection classes ”

ArrayList : A 1-D, resizable array of objects. The size of a traditional array cannot be changed once it is created. An ArrayList can grow or shrink as needed.

HashMap : A hash table implementation of the Map interface. The Map interface defines a collection that stores a series of key-value pairs. A HashMap stores its elements in "buckets." The size of the HashMap is automatically increased when the storage amount reaches a specified load factor. The elements of a HashMap are not sorted. There is no structure to the ordering of the elements of a HashMap and the element order may change over time.

HashSet : A hash table implementation of the Set interface. This interface defines a collection with no duplicate pairs. An attempt to add an element to the collection that already contains the element will fail. There is no ordering of the elements of a HashSet .

Hashtable : A hash table is a collection of key-value pairs. This is an older collection class. The Java 1.1 implementation of the Hashtable class was updated in Java 1.2 to implement the Map interface.

LinkedHashMap : A HashMap that maintains its elements in a doubly linked list. The order of the elements in the collection will remain constant.

LinkedHashSet : A HashSet that maintains its elements in a doubly linked list. The order of the elements in the collection will remain constant.

LinkedList : A collection of objects stored as a linked list.

Stack : A last-in-first-out collection of objects. The objects are added to and removed from the top of the stack using the push() and pop() methods. You can examine the element at the top of the stack using the peek() method.

TreeMap : A collection of key-value pairs stored in a tree structure.

TreeSet : A tree structure collection of key-value pairs with no duplicate elements. An attempt to add a value that already exists in the TreeSet will fail.

Vector : A collection of objects whose size can grow or shrink according to the number of elements in the collection.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net