Skip to Content
Java Coding Problems
book

Java Coding Problems

by Anghel Leonard
September 2019
Intermediate to advanced
816 pages
18h 47m
English
Packt Publishing
Content preview from Java Coding Problems

Checking whether two arrays are equal

Checking whether two arrays are equal can be easily accomplished via the Arrays.equals() method. This flag method comes in many flavors for primitive types, Object, and generics. It also supports comparators.

Let's consider the following three arrays of integers:

int[] integers1 = {3, 4, 5, 6, 1, 5};int[] integers2 = {3, 4, 5, 6, 1, 5};int[] integers3 = {3, 4, 5, 6, 1, 3};

Now, let's check whether integers1 is equal to integers2, and whether integers1 is equal to integers3. This is very simple:

boolean i12 = Arrays.equals(integers1, integers2); // trueboolean i13 = Arrays.equals(integers1, integers3); // false

The preceding examples check whether two arrays are equal, but we can check whether two segments ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Coding Problems - Second Edition

Java Coding Problems - Second Edition

Anghel Leonard
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9781789801415Supplemental Content