Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

482 Part II: The Java Library


ThedeepEquals( )method can be used to determine if two arrays, which might contain
nested arrays, are equal. It has this declaration:

static boolean deepEquals(Object[ ]a, Object[ ]b)

It returnstrueif the arrays passed inaandbcontain the same elements. Ifaandbcontain
nested arrays, then the contents of those nested arrays are also checked. It returnsfalseif
the arrays, or any nested arrays, differ.
Thefill( )method assigns a value to all elements in an array. In other words, it fills an
array with a specified value. Thefill( )method has two versions. The first version, which
has the following forms, fills an entire array:

static void fill(booleanarray[ ], booleanvalue)
static void fill(bytearray[ ], bytevalue)
static void fill(chararray[ ], charvalue)
static void fill(doublearray[ ], doublevalue)
static void fill(floatarray[ ], floatvalue)
static void fill(intarray[ ], intvalue)
static void fill(longarray[ ], longvalue)
static void fill(shortarray[ ], shortvalue)
static void fill(Objectarray[ ], Objectvalue)

Here,valueis assigned to all elements inarray.
The second version of thefill( )method assigns a value to a subset of an array. Its forms
are shown here:

static void fill(booleanarray[ ], intstart, intend, booleanvalue)
static void fill(bytearray[ ], intstart, intend, bytevalue)
static void fill(chararray[ ], intstart, intend, charvalue)
static void fill(doublearray[ ], intstart, intend, doublevalue)
static void fill(floatarray[ ], intstart, intend, floatvalue)
static void fill(intarray[ ], intstart, intend, intvalue)
static void fill(longarray[ ], intstart, intend, longvalue)
static void fill(shortarray[ ], intstart, intend, shortvalue)
static void fill(Objectarray[ ], intstart, intend, Objectvalue)

Here,valueis assigned to the elements inarrayfrom positionstartto positionend–1. These
methods may all throw anIllegalArgumentExceptionifstartis greater thanend,or an
ArrayIndexOutOfBoundsExceptionifstartorendis out of bounds.
Thesort( )method sorts an array so that it is arranged in ascending order. Thesort( )
method has two versions. The first version, shown here, sorts the entire array:

static void sort(bytearray[ ])
static void sort(chararray[ ])
static void sort(doublearray[ ])
static void sort(floatarray[ ])
static void sort(intarray[ ])
static void sort(longarray[ ])
static void sort(shortarray[ ])
static void sort(Objectarray[ ])
static <T> void sort(Tarray[ ], Comparator<? super T>c)
Free download pdf