A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/array_compare.htm below:

How to compare two arrays in Java

How to compare two arrays in Java Problem Description

How to compare two arrays?

Solution

Following example uses equals method to check whether two arrays are 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

java_arrays.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4