Java Arrays Cheat Sheet

Essential methods from Java 8 to Java 17

Sorting Methods

sort(array)
Arguments: 1

Sorts the entire array into ascending order.

sort(array, from, to)
Arguments: 3

Sorts the specified range of the array into ascending order.

parallelSort(array)
Arguments: 1

Sorts the array using parallel sort (multi-threading).

parallelSort(array, from, to)
Arguments: 3

Sorts the specified range of the array using parallel sort.

Searching Methods

binarySearch(array, key)
Arguments: 2

Searches the specified array for the specified key using binary search.

binarySearch(array, from, to, key)
Arguments: 4

Searches a range of the array for the specified key using binary search.

Comparing Methods

equals(array1, array2)
Arguments: 2

Checks if two arrays are equal (same elements in same order).

deepEquals(array1, array2)
Arguments: 2

Deep comparison for multi-dimensional arrays.

compare(array1, array2)
Arguments: 2

Lexicographic comparison of two arrays.

mismatch(array1, array2)
Arguments: 2

Finds the first index where arrays differ.

Copying & Filling Methods

copyOf(array, newLength)
Arguments: 2

Copies array to a new array of specified length.

copyOfRange(array, from, to)
Arguments: 3

Copies a subrange of the array.

fill(array, value)
Arguments: 2

Fills entire array with the specified value.

fill(array, from, to, value)
Arguments: 4

Fills part of the array with the specified value.

setAll(array, generator)
Arguments: 2

Sets values using a generator function.

parallelSetAll(array, generator)
Arguments: 2

Parallel version of setAll.

Conversion Methods

asList(...elements)
Arguments: Varargs

Converts array to a fixed-size list.

toString(array)
Arguments: 1

Converts 1D array to a readable string.

deepToString(array)
Arguments: 1

Converts multi-dimensional array to string.

hashCode(array)
Arguments: 1

Returns hash code for 1D array.

deepHashCode(array)
Arguments: 1

Returns hash code for multi-dimensional array.

stream(array)
Arguments: 1

Creates stream from array elements.

spliterator(array)
Arguments: 1

Creates spliterator from array.

Utility Methods

parallelPrefix(array, op)
Arguments: 2

Performs parallel prefix operation on array.

equals(array, start, end, other, oStart, oEnd)
Arguments: 6

Compares ranges of two arrays.

compare(array, start, end, other, oStart, oEnd)
Arguments: 6

Lexicographic comparison of array ranges.