Prior to the SDK version 1.2, there was no collections "framework" in Java. Java contained two main workhorse collectionsjava.util.Vector and java.util.Hashtable[6]that still exist today. The analogous classes in modern Java are respectively java.util.ArrayList and java.util.HashMap. The class java.util.HashMap provides similar functionality as the class java.util.EnumMap, with which you are already familiar. Refer to Lesson 9 for more information on HashMap.
Both Vector and Hashtable are concrete; they implement no common interfaces. They incorporate support for multithreaded programming[7] by default, a choice that often results in unnecessary overhead. Unfortunately, today you will still encounter a large amount of code that uses or requires use of the Vector class.
Since there were no corresponding interfaces for these classes in the initial versions of Java, you were forced to assign Vector or Hashtable instances to a reference to an implementation class: Vector names = new Vector(); With the introduction of the collections framework, Sun retrofitted the Vector class to implement the List interface and the Hashtable class to implement the Map interface. You might for some reason be stuck with continuing to use a Vector or Hashtable. If so, you may be able to migrate to a modern approach by assigning the instance to an interface reference: List names = new Vector(); Map dictionary = new Hashtable(); Sun also retrofitted Vector and Hashtable so that they are parameterized types. You can thus code: List<String> names = new Vector<String>(); Map<Student.Grade,String> dictionary = new Hashtable<Student.Grade,String>(); |