Compare Two int Arrays using Arrays.equals method - Java java.util

Java examples for java.util:Arrays

Introduction

static boolean equals(int array1[], int array2[]) method returns true if both arrays are equal.

Arrays are considered as equal if they contain same elements in same order.

Demo Code

 
import java.util.Arrays;
 
public class Main {
 
  public static void main(String[] args) {
    int[] intArray1 = new int[]{217,178,1023};
    int[] intArray2 = new int[]{217,178,1023};
   // w  w  w .j  ava  2 s . c o m
    boolean blnResult = Arrays.equals(intArray1,intArray2);
    System.out.println("Are two int arrays equal ? : " + blnResult);
   
    /*
      two int array references pointing to null are considered as equal.
    */
    
    intArray1 = null;
    intArray2 = null;
    
    blnResult = Arrays.equals(intArray1,intArray2);
    System.out.println("Are two int arrays equal ? : " + blnResult);
  }
}

Result


Related Tutorials