September 2019
Intermediate to advanced
816 pages
18h 47m
English
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 ...