|
|
|
TimeThe Time package has four classes: DateFormatUtils , DateUtils , FastDateFormat , and StopWatch . Both DateFormatUtils and FastDateFormat serve to make it easier to render dates into strings. FastDateFormat is a quick, thread-safe implementation of a date and time formatter. DateFormatUtils includes several FastDateFormat objects, preconfigured for different uses, including different ISO8601 formats as well as an SMTP format. The StopWatch class allows you to perform timings much like a stopwatchit allows you to start a timer, perform a split, stop, reset, and so on. Note that the StopWatch class is really only a holder for time values from System.currentTimeMillis() there is no notion of a scheduler or execution thread. Interestingly, the code:
StopWatch testWatch = new StopWatch();
try {
testWatch.start();
Thread.sleep(1000);
testWatch.stop();
System.out.println(testWatch.getTime());
} catch (Exception e) { e.printStackTrace(); }
. . . returns a value of 1001. |
|
|
|
|
|
|
SummaryAlthough the Lang package offers a wide suite of packages, it can be hard to keep track of the various capabilities. This chapter provides an overview, but for more detail on the base classes and the time package, see Appendix A
Almost every Java application can benefit from
the Lang package. Similarly, many programs can benefit from the
Collections package, described in the
|
|
|
|
|
|
|
Chapter 11. Collections
The
Table 11-1
Table 11-1. Collection Features
java.util.Map myMap = new java.util.HashMap(); For more information on the built-in JDK 1.4 collections, see http://java.sun.com/j2se/1.4.2/docs/guide/collections/reference.html. Note that this chapter does not duplicate information included in the default JDK documentationfor example, the Stack and SortedMap interfaces are concepts covered as part of the standard Java collection interface.
The meaning of each column heading in Table 11-1 is as
|
|
|
|