Article
home/blog/Loading

Compare arrays with Java

There are many such use cases where you will find yourself required to compare two arrays in Java.

Remembering a few of the different ways to do so is a tool which should be in any programmers toolbox.

Compare using Java 8

IntStream.range(0, arr.length)
    .forEach((i) -> arr[i] == b.get(i))

Compare using Java 5+

return Arrays.deepEquals(arr1, arr2);