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

 

package testjava.javatest;

import java.util.Arrays;

public class EqualIntegerArrays
{
	public static void main(String args[])
	{
        String[] firstString = {"this", "is", "programs", "buzz"}; 
        String[] secondString = {"is", "this", "programs", "buzz"};
        String[] thirdString = {"yes", "its", "programs", "buzz"};
        
        Arrays.sort(firstString);
        Arrays.sort(secondString);
        Arrays.sort(thirdString);

        System.out.println(Arrays.equals(firstString, secondString));        //Output : true
        System.out.println(Arrays.equals(firstString, thirdString));      //Output : false
	}   
}

Output

true

false