Note- Even if order of the string values different in the arrays then also it will say arrays are not same. Both the arrays should have same elements in same order then it will say, both the array are same.

import java.util.Scanner;

public class CompareArray {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println(“Enter size of string array: “);
        int size = in.nextInt();
        String[] array1 = new String[size];
        String[] array2 = new String[size];
        System.out.println(“enter the element of 1st array: “);
        for(int i=0; i<size; i++){
            array1[i] = in.next();
        }
        System.out.println(“enter the element of 2nd array: “);
        for(int i=0; i<size; i++){
            array2[i] = in.next();
        }
        
        String s1=””, s2 =””;
        for(int i=0; i<size; i++){
            s1 = s1+array1[i];
            s2 = s2+array2[i];
        }
        if(s1.equals(s2)){
            System.out.println(“both the array have same elements.”);
            System.out.println(s1);
            System.out.println(s2);
        }else{
            System.out.println(“both the array does not have the same elements.”);
            System.out.println(s1);
            System.out.println(s2);
        }
    }
}

 

Source: http://selenium-makeiteasy.blogspot.com