The java.util.Arrays class is the standard toolbox for working with arrays. Use Arrays.sort to sort, Arrays.binarySearch to find a value in a sorted array, Arrays.fill to set every element, and Arrays.toString to print an array. This guide explains the arrays class java methods you will use most, with small complete examples.
All methods are static, so you call them as Arrays.sort(numbers) without creating an object. Import the class with import java.util.Arrays;.
Printing an array directly shows a type code and a hash, not the contents. Arrays.toString gives a readable form, and Arrays.deepToString handles nested arrays.
The == operator compares references, so it is false for two separate arrays. Arrays.equals compares length and elements. Use Arrays.deepEquals for nested arrays.
Arrays.sort sorts in place in ascending order. For primitive arrays it uses a dual-pivot quicksort. For object arrays it uses a stable merge-sort variant (TimSort), so equal elements keep their original order.
The range form takes a start index (inclusive) and an end index (exclusive). For a custom order on objects, pass a Comparator. A comparator works only with object arrays such as String[] or Integer[], not with int[].
For very large primitive arrays, Arrays.parallelSort can use several cores, but it only pays off for large inputs.
binarySearch finds an element in O(log n) time, but the array must already be sorted in the same order. On an unsorted array the result is undefined.
If the value is found, you get its index. If not, you get -(insertionPoint) - 1. Here 10 would be inserted at index 2, so the result is -3. Decode it with int insertionPoint = -result - 1;. If the array contains duplicates, any matching index may be returned.
Arrays.fill sets every element, or a range, to one value.
Arrays have a fixed length, so copyOf is how you "resize": it returns a new array, padded with zeros, false or null when longer, and truncated when shorter. Copies of object arrays are shallow, so both arrays point to the same objects.
Arrays.asList wraps an object array as a fixed-size list. It does not copy, and writes pass through to the array. You can set elements but cannot add or remove them. For a primitive array it would produce a list with one element, the array itself, so use Integer[] or a stream.
For an independent, modifiable list, use new ArrayList<>(Arrays.asList(words)). For an immutable one, use List.of(words).
No. It sorts the array you pass in place and returns nothing. Copy first with Arrays.copyOf if you need to keep the original order.
Not directly. Sort ascending and reverse it, or use Integer[] with Comparator.reverseOrder(), or Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).
It means the value is not present. Use -result - 1 to get the index where it would be inserted to keep the array sorted.
No. Arrays.asList is a fixed-size view backed by the array, and List.of creates an immutable list that rejects null.
The Arrays class gives you sort, binarySearch, fill, copyOf, equals, toString and asList. Remember that sorting is in place, binary search needs a sorted array, copyOf returns a new array, and Arrays.asList is a fixed-size view over the original.