java.util · java.base · since Java 1.2

Arrays

declaration
public final class Arrays

Static utilities for raw arrays: sort, parallel sort, binary search, fill, copy, comparison, hashing, streaming, and the fixed-size asList view.

Key methods

static void sort(int[] a) / sort(int[] a, int from, int to)Dual-pivot quicksort for primitives; ranged variant sorts a slice.
static <T> void sort(T[] a, Comparator<? super T> c)Stable TimSort for objects; null comparator = natural order.
static void parallelSort(int[] a) / parallelSort(a, from, to) / parallelSort(T[], Comparator)Fork/join parallel sort — wins on large arrays, same result.
static int binarySearch(int[] a, int key) / binarySearch(a, from, to, key)Sorted arrays only; negative return = -(insertion point) - 1.
static <T> T[] copyOf(T[] a, int newLength)Grow/shrink via copy; padded with null/0/false.
static <T> T[] copyOfRange(T[] a, int from, int to)Copy a slice into a fresh array.
static void fill(long[] a, long v) / fill(a, from, to, v)Bulk assignment, whole array or slice.
static <T> void setAll(T[] a, IntFunction<? extends T> gen)Populate by index via a generator function.
static boolean equals(int[] a, int[] b) / deepEquals(Object[], Object[])Content comparison (== on arrays is identity!); deep recurses nested arrays.
static int hashCode(int[] a) / deepHashCode(Object[] a)Content-based hash — arrays do not override hashCode themselves.
static String toString(int[] a) / deepToString(Object[] a)Readable printing; deep recurses nested arrays.
static int compare(int[] a, int[] b) / mismatch(int[] a, int[] b)Lexicographic compare/mismatch: mismatch returns the first differing index, or the length of the shorter array if one is a proper prefix of the other, or -1 if fully equal.
static <T> List<T> asList(T... a)Fixed-size, write-through List view — add/remove throw.
static IntStream stream(int[] a) / stream(a, from, to)Array-to-stream bridge, whole array or slice.

Example

Java
int[] a = { 5, 2, 8, 1 };
Arrays.sort(a);                       // [1, 2, 5, 8]
int i = Arrays.binarySearch(a, 5);    // 2
int[] b = Arrays.copyOfRange(a, 0, 2); // [1, 2]
String s = Arrays.toString(a);        // "[1, 2, 5, 8]"
int firstDiff = Arrays.mismatch(a, b); // 2  (b is a proper prefix of a → length of the shorter array)
The everyday array toolkit — sort, search, slice, compare.