adsense


Showing posts with label JAVA EXAMPLES CHECK EQUALITY OF TWO ARRAYS. Show all posts
Showing posts with label JAVA EXAMPLES CHECK EQUALITY OF TWO ARRAYS. Show all posts

Sunday, 25 October 2015

JAVA EXAMPLES CHECK EQUALITY OF TWO ARRAYS PAGE 57

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES CHECK EQUALITY OF TWO ARRAYS


Java Examples - Check equality of two arrays


Problem Description:
How to check if two arrays are equal or not?
Solution:
Following example shows how to use equals () method of Arrays to 
check if two arrays are equal or not.
import java.util.Arrays;

public class Main {
   public static void main(String[] args) throws Exception {
      int[] ary = {1,2,3,4,5,6};
      int[] ary1 = {1,2,3,4,5,6};
      int[] ary2 = {1,2,3,4};
      System.out.println("Is array 1 equal to array 2?? "
      +Arrays.equals(ary, ary1));
      System.out.println("Is array 1 equal to array 3?? "
      +Arrays.equals(ary, ary2));
   }
}
Result:
The above code sample will produce the following result.
Is array 1 equal to array 2?? true
Is array 1 equal to array 3?? false