Java Program to Compare two Double Arrays
Java double array is used to store double data type values only. The default value of the elements in a double array is 0.
We can compare two double arrays by two ways:
- By naive approach of traversing through the whole array and comparing each element.
- By Arrays.equals() method.
Method 1: Naive Approach
- By Comparing one element at a time by traversing through both the arrays using for loop.
Arrays are not Equal
Time Complexity: O(n)
Method 2: Using Arrays.equals() method
public static boolean equals(int a, int a2)
- a1 – one array to be tested for equality
- a2 – the other array to be tested for equality
Returns : true if the two arrays are equal
Arrays are Equal
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.