Write a Java Program to check for the equality of two integer arrays in java?

 

package testjava.javatest;

import java.util.Arrays;

public class EqualIntegerArrays
{
	public static void main(String args[])
	{
		int[] firstArray  = {1, 3, 2, 5, 4};
		int[] secondArray = {1, 2, 3, 4, 5};
		
		boolean equalOrNot = checkArrayEquals(firstArray, secondArray);
		
		if(equalOrNot)
			System.out.println("Both Arrays are equal");
		else
			System.out.println("Arrays are not equal");
	}
	
	static boolean checkArrayEquals(int[] array1, int[] array2)
	{
		boolean isEqual = true;
		
		Arrays.sort(array1);
		Arrays.sort(array2);
		
		if(array1.length == array2.length)
		{
			for(int i = 0; i < array1.length; i++)
			{
				if(array1[i] != array2[i])
				{
					isEqual = false;
				}
			}
		}
		else
		{
			isEqual = false;
		}
		
		return isEqual;
	}
}

Output: Both Arrays are equal.