java.util.Arrays Class

The Arrays class provides static methods to manipulate arrays. Table 6.1 shows some of its methods.

Method

Description

asList

Returns a fixed-size List backed by the array. No other elements can be added to the List. List is discussed in Chapter 14, “The Collection Framework.”

binarySearch

Searches an array for the specified key. If the key is found, returns the index of the element. If there is no match, returns the negative value of the insertion point minus one. See the section “Searching An Array” for details.

copyOf

Creates a new array having the specified length. The new array will have the same elements as the original array. If the new length is not the same as the length of the original array, it pads the new array with null or default values or truncates the original array.

copyOfRange

Creates a new array based on the specified range of the original array.

equals

Compares the contents of two arrays.

fill

Assigns the specified value to each element of the specified array.

sort

Sorts the elements of the specified array.

parallelSort

Parallel sorts the elements of the specified array.

toString

Returns the string representation of the specified array.