Java Reference
In-Depth Information
class definition. There is no need for a semicolon at the end of the closing brace,
though including one is not an error.
Enumerated types can do a lot more than replace constants. One nice feature
is the ability to obtain an array of all the enumerated type values within an enum :
Season[] seasons = Season.values ();
For more about the enumerated type, we refer you to the online API documentation
[3] and the topics referenced in Chapter 1 that cover the new features in J2SE 5.0
[1,2].
10.10 The Arrays class
The class java.util.Arrays provides a number of static methods for filling,
searching, sorting, and comparing arrays. For each method name, there are sev-
eral overloaded versions that differ according to the type of the array or array
arguments. We examine several of these in more detail here.
10.10.1 Arrays.equals()
Let's consider the equals() method (actually methods , since there are several
overloaded versions). There is one for each primitive type plus one more for
Object arrays:
boolean equals ( type [] array1, type [] array2)
These compare two input arrays of the same type for equality. The methods
return true if each array holds the same number of elements and each element in
array1 equals the value in the corresponding element in array2 .For the case
of Object arrays, the references in the two corresponding elements must either
point to the same object or both equal null .
10.10.2 Arrays.fill()
There are two forms of the fill() methods:
void fill ( type [] array, type value)
void fill ( type [] array, int fromIndex, int toIndex, type
value)
The first version of the overloaded fill methods, one for each primitive type
and for Object , fill all elements in array of the same type with the value
argument. The second version fills those elements between the given indices.
Search WWH ::




Custom Search