Java Collection Tutorial - Java Arrays.equals(Object [] a, Object [] a2)








Syntax

Arrays.equals(Object [] a, Object [] a2) has the following syntax.

public static boolean equals(Object [] a,  Object [] a2)

Example

In the following code shows how to use Arrays.equals(Object [] a, Object [] a2) method.

/*w  w  w  .j  a va2 s .c  om*/

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
  
    Object[] arr1 = new Object[] { 1, 123 };
    Object[] arr2 = new Object[] { 1, 123, 22, 4 };
    Object[] arr3 = new Object[] { 1, 123 };
    
    System.out.println(Arrays.equals(arr1, arr2));

    System.out.println(Arrays.equals(arr1, arr3));
  }
}

The code above generates the following result.