How do we compare two arrays in Java?



You can compare two arrays in Java using the compare() method of the Arrays class.

Example

Live Demo

import java.util.Arrays;

public class ComparingArrays {
   public static void main(String args[]) {
      String[] myArray1 = {"JavaFX", "HBase", "OpenCV", "WebGL", "FlexBox"};
      String[] myArray2 = {"JavaFX", "HBase", "OpenCV", "WebGL", "FlexBox"};
      Boolean result = Arrays.equals(myArray1, myArray2); System.out.println(result);
   }
}

Output

true
Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician


Advertisements