21. The Package java.util
The Package java.util
Notable among these utilities is the
Enumeration interface. An object that implements this interface will generate a series of items, delivering them on demand, one by one. Container classes such as
Vector provide one or more methods that return an
Date provides a convenient way to represent and manipulate time and date information. Dates may be constructed from a year, month, day of month, hour, minute, and second, and those six components, as well as the day of the week, may be extracted from a date. Time zones and daylight saving time are properly accounted for.
Dictionary represents a collection of key-value pairs and allows a value to be fetched given the key. The class
Hashtable is one concrete implementation of
Dictionary. The class
Hashtable by allowing one table to provide default values for another and by providing standard means for reading entries from files and writing entries to files.
Observable provides a mechanism for notifying other objects, called "observers," whenever an
Observable object is changed. An observer object may be any object that implements the
Observer interface. (This notification mechanism is distinct from that provided by the
notify methods of class
Object (§20.1) and is not connected with the thread scheduling mechanism.)
Random provides an extensive set of methods for pseudorandomly generating numeric values of various primitive types and with various distributions. Each instance of class
Random is an independent pseudorandom generator.
StringTokenizer provides an easy way to divide strings into tokens. The set of characters that delimit tokens is programmable. The tokenizing method is much simpler than the one used by the class
java.io.StreamTokenizer. For example, a
StringTokenizer does not distinguish among identifiers, numbers, and quoted strings; moreover, it does not recognize and skip comments.
Stack are simple container classes that provide extensions to the capabilities of Java arrays. A
Vector, unlike a Java array, can change its size, and many convenient methods are provided for adding, removing, and searching for items. A
Stack is a
Vector with additional operations such as
The hierarchy of classes defined in package
java.util is as follows. (Classes whose names are shown here in
boldface are in package
java.util; the others are in package
java.lang and are shown here to clarify subclass relationships.)
Object §20.1 interface
§20.22 Exception RuntimeException