JDK (Java Development Kit) Tutorials
Dr. Herong Yang, Version 5.00

HashSet, Vector, HashMap and Collection Classes

This chapter provides tutorial notes and example codes on collection classes. Topics include collection types: Set, List and Map; data structure types: Array, Linked List, Binary Tree, and Hash Table; commonly used JDK collection classes: HashSet, Vector, HashMap; search operation performance comparison; Comparable interface and compareTo() method.

Types of Collections-of-Elements

Data Structures of Collection Implementations

Collection Implementations in JDK 1.4.1

Search Operation Performance of Different Collection Classes

Comparable Interface and compareTo() Method

Conclusion:

  • There are 3 main collection types: Set, List and Map.
  • There are 4 main data structures, Array, Linked List, Binary Tree, and Hash Table, for implementing collections.
  • JDK 1.4.1 provides 12 collection implementation classes: TreeSet, HashSet, LinkedHashSet, ArrayList, LinkedList, Vector, Stack, TreeMap, HashMap, IdentityHashMap, WeakHashMap, Hashtable.
  • HashSet and LinkedHashSet classes have the best performance on search operations.
  • TreeSet class requires that objects to be constructed with the Comparable interface.

Sample programs listed in this chapter have been tested with JDK 1.3.1, 1.4.1 and 1.5.0.

Dr. Herong Yang, updated in 2008
HashSet, Vector, HashMap and Collection Classes