Java Arrays Methods

Beginner
6 min read
Updated: Nov 2026
21 method guides
Method index

About This Index

This page is the Java Arrays Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, so the output shown is the output you get.

Learn what the Arrays class is on the Arrays hub. Use this page when you need a specific method such as toString(), sort(), or copyOf(). The examples compile on Java 8 and later, except on the three Java 9 pages listed below.

All methods are static.

You always write Arrays.methodName(array, ...); the class cannot be instantiated. Arrays themselves keep a fixed length, so methods that "grow" or "shrink" an array, such as copyOf(), return a new array. compare(), compareUnsigned(), and mismatch() need Java 9 or newer.

How to Call an Arrays Method

Import java.util.Arrays once, then pass your array as the first argument:

Java
import java.util.Arrays;

int[] nums = {5, 3, 9, 1};
Arrays.sort(nums);                          // nums is now 1, 3, 5, 9
System.out.println(Arrays.toString(nums));  // [1, 3, 5, 9]
int pos = Arrays.binarySearch(nums, 5);     // 2
int[] bigger = Arrays.copyOf(nums, 6);      // [1, 3, 5, 9, 0, 0]
Arrays.fill(bigger, 4, 6, 7);               // [1, 3, 5, 9, 7, 7]

Java Arrays Methods Table

All method guides in this Java tutorial series (21 tutorials), grouped by purpose.

Print and convert

3 methods

Turn an array into readable text, including nested arrays, or view it as a fixed-size List.

MethodDescriptionTutorial
toString()Print a one-dimensional array as readable text.Try it
deepToString()Print nested arrays such as int[][] as readable text.Try it
asList()View an array as a fixed-size List backed by the array.Try it

Copy

2 methods

Make a new array from an existing one: a longer or shorter copy, or a slice between two indexes.

MethodDescriptionTutorial
copyOf()Copy an array into a new one that is longer or shorter.Try it
copyOfRange()Copy a slice of an array, from one index up to another.Try it

Fill and set

3 methods

Put one value into every slot (or a range), or compute each element from its index.

MethodDescriptionTutorial
fill()Put the same value into every slot, or into a range.Try it
setAll()Compute every element from its index with a function.Try it
parallelSetAll()Compute every element from its index, in parallel.Try it

Compare

5 methods

Check whether two arrays hold the same elements, order them, or find where they first differ. compare, compareUnsigned, and mismatch need Java 9.

MethodDescriptionTutorial
equals()Check whether two arrays have the same length and elements.Try it
deepEquals()Compare nested arrays such as int[][] by their contents.Try it
compare()Order two arrays lexicographically: negative, zero, or positive (Java 9).Try it
compareUnsigned()Compare integer arrays as unsigned numbers (Java 9).Try it
mismatch()Find the first index where two arrays differ, or -1 (Java 9).Try it

Hash codes

2 methods

Compute a hash code from the contents of an array, for flat or nested arrays.

MethodDescriptionTutorial
hashCode()Compute a hash code from the contents of an array.Try it
deepHashCode()Compute a content-based hash code for nested arrays.Try it

Cumulative operations

1 method

Replace every element with a running result such as a running total or running maximum.

MethodDescriptionTutorial
parallelPrefix()Replace each element with a running total (or running max, product, ...).Try it

Iterate and stream

2 methods

Walk the elements with a Spliterator or process them with the Stream API.

MethodDescriptionTutorial
spliterator()Get a Spliterator over an array or a range of it.Try it
stream()Process an array with the Stream API: sum, filter, map, collect.Try it

Frequently Asked Questions

java.util.Arrays is a utility class full of static methods for working with arrays: printing, sorting, searching, copying, filling, comparing, hashing, and turning an array into a List or a stream. You never create an Arrays object; you call Arrays.sort(a), Arrays.toString(a), and so on.
This index lists 21 guides, from asList() and binarySearch() to stream() and toString(), grouped by what they do. Most methods have one overload per primitive array type plus one for object arrays.
compare(), compareUnsigned(), and mismatch() were added in Java 9, along with range and Comparator overloads of equals(). setAll(), parallelSetAll(), parallelSort(), parallelPrefix(), spliterator(), and stream() need Java 8. Everything else works on older versions too.
Arrays do not override toString(), so println prints the type code and a hash, not the elements. Use Arrays.toString(a) for a flat array and Arrays.deepToString(a) for an array of arrays.
Read the Java Arrays hub first. Then open toString(), sort(), copyOf(), and equals() from the tables below; they cover most everyday array work.

Start with toString()

Print an array as readable text instead of a type code and hash.

toString() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful