Java Reference
In-Depth Information
continued
This declares a list of integer arrays. As arrays are proper, non‐primitive classes, it's
fine to use them as generic parameters. It's even possible to define a list that's hold-
ing lists of integers, like so:
ArrayList<ArrayList<Integer>> aList =
new ArrayList<ArrayList<Integer>>();
By combining collections in this manner, it's easy to define complex custom data
structures to hold complex information. Don't go overboard with this however.
When you find yourself declaring maps of lists of sets, it might be better to abstract
some of this hierarchical complexity by creating some additional classes instead.
Other Utility Classes
Besides collection classes, the java.util package also contains a number of other helpful classes to
provide a great deal of functionality. These include:
java.util.Arrays : This class contains a large number of static helper methods to sort
and search arrays. Note, however, that the arraycopy method is part of the java.lang.
System class (you saw this method in the SetAsArray class). The reason for this is that this
method directly performs a memory operation and is thus closer to a “system operation”
than what the methods provided by arrays do. Another reason is the fact that java.util.
Arrays was introduced in Java 1.2, whereas the arraycopy method existed before that
point.
java.util.Date : A class to deal with dates and time. While this class provides solid support
for working with dates and time, proper date and time support has been the thorn in the eye
of many Java developers, as this class rapidly ceases to be useful once complex aspects such
as multiple time zones come into play. The class is also not very well designed. For example,
years start counting at 1990, months at 1, and days at 0 (!), which is not very intuitive. This
is exactly why Java SE 8 introduced a new Date and Time API, which is located in its proper
package: java.time . Whenever possible, it is highly advisable to use this class instead of the
older ones.
java.util.Calendar : A class that provides methods to convert between a point in time and
a set of calendar fields. This can be helpful to retrieve the year, month, day, and so on for a
given Date object. This class has been updated in Java SE 8 as well, with better support for
internalization.
java.util.Currency : A class to represent a currency.
java.util.Locale : A class to represent a geographical, political, or cultural region. This
class has been updated in Java SE 8 as well.
java.util.Random : A class providing a random number generator.
java.util.Scanner : A class providing a text scanner that can parse texts. You will utilize
this class to parse text files in Chapter 7.
 
Search WWH ::




Custom Search