How do we compare two arrays in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 09-Jan-2018 05:37:23
Advertisements