Arrays

public class Arrays extends Object

This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.

The methods in this class all throw a NullPointerException, if the specified array reference is null, except where noted.

The documentation for the methods contained in this class includes briefs description of the implementations. Such descriptions should be regarded as implementation notes, rather than parts of the specification. Implementors should feel free to substitute other algorithms, so long as the specification itself is adhered to. (For example, the algorithm used by sort(Object[]) does not have to be a MergeSort, but it does have to be stable.)

This class is a member of the Java Collections Framework.

Public Method Summary

static <T> List<T>
asList(T... a)
Returns a fixed-size list backed by the specified array.
static int
binarySearch(char[] a, int fromIndex, int toIndex, char key)
Searches a range of the specified array of chars for the specified value using the binary search algorithm.
static int
binarySearch(long[] a, long key)
Searches the specified array of longs for the specified value using the binary search algorithm.
static int
binarySearch(float[] a, int fromIndex, int toIndex, float key)
Searches a range of the specified array of floats for the specified value using the binary search algorithm.
static int
binarySearch(byte[] a, int fromIndex, int toIndex, byte key)
Searches a range of the specified array of bytes for the specified value using the binary search algorithm.
static int
binarySearch(long[] a, int fromIndex, int toIndex, long key)
Searches a range of the specified array of longs for the specified value using the binary search algorithm.
static int
binarySearch(int[] a, int fromIndex, int toIndex, int key)
Searches a range of the specified array of ints for the specified value using the binary search algorithm.
static int
binarySearch(short[] a, int fromIndex, int toIndex, short key)
Searches a range of the specified array of shorts for the specified value using the binary search algorithm.
static <T> int
binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)
Searches a range of the specified array for the specified object using the binary search algorithm.
static int
binarySearch(byte[] a, byte key)
Searches the specified array of bytes for the specified value using the binary search algorithm.
static int
binarySearch(short[] a, short key)
Searches the specified array of shorts for the specified value using the binary search algorithm.
static int
binarySearch(Object[] a, Object key)
Searches the specified array for the specified object using the binary search algorithm.
static int
binarySearch(double[] a, int fromIndex, int toIndex, double key)
Searches a range of the specified array of doubles for the specified value using the binary search algorithm.
static int
binarySearch(Object[] a, int fromIndex, int toIndex, Object key)
Searches a range of the specified array for the specified object using the binary search algorithm.
static int
binarySearch(char[] a, char key)
Searches the specified array of chars for the specified value using the binary search algorithm.
static int
binarySearch(int[] a, int key)
Searches the specified array of ints for the specified value using the binary search algorithm.
static int
binarySearch(double[] a, double key)
Searches the specified array of doubles for the specified value using the binary search algorithm.
static <T> int
binarySearch(T[] a, T key, Comparator<? super T> c)
Searches the specified array for the specified object using the binary search algorithm.
static int
binarySearch(float[] a, float key)
Searches the specified array of floats for the specified value using the binary search algorithm.
static double[]
copyOf(double[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static float[]
copyOf(float[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static boolean[]
copyOf(boolean[] original, int newLength)
Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.
static int[]
copyOf(int[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static long[]
copyOf(long[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static short[]
copyOf(short[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static <T, U> T[]
copyOf(U[] original, int newLength, Class<? extends T[]> newType)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
static <T> T[]
copyOf(T[] original, int newLength)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
static char[]
copyOf(char[] original, int newLength)
Copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length.
static byte[]
copyOf(byte[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
static double[]
copyOfRange(double[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static <T> T[]
copyOfRange(T[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static char[]
copyOfRange(char[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static float[]
copyOfRange(float[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static long[]
copyOfRange(long[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static int[]
copyOfRange(int[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static boolean[]
copyOfRange(boolean[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static <T, U> T[]
copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
Copies the specified range of the specified array into a new array.
static short[]
copyOfRange(short[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static byte[]
copyOfRange(byte[] original, int from, int to)
Copies the specified range of the specified array into a new array.
static boolean
deepEquals(Object[] a1, Object[] a2)
Returns true if the two specified arrays are deeply equal to one another.