- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compare Two Java double arrays
To compare two Java double arrays, use the Arrays.equals() method. The following are our double arrays.
double[] arr1 = new double[] { 1.3, 7.2, 4.2 }; double[] arr2 = new double[] { 1.3, 7.2, 4.2 }; double[] arr3 = new double[] { 2.8, 5.3, 9.8 }; double[] arr4 = new double[] { 2.9, 5.8, 7.8 };
Now, let us compare the above arrays. Two of these arrays will be compared at once.
Arrays.equals(arr1, arr2); Arrays.equals(arr1, arr3); Arrays.equals(arr1, arr4);
The following is the final example to compare Java double arrays.
Example
import java.util.*; public class Demo { public static void main(String args[]) { double[] arr1 = new double[] { 1.3, 7.2, 4.2 }; double[] arr2 = new double[] { 1.3, 7.2, 4.2 }; double[] arr3 = new double[] { 2.8, 5.3, 9.8 }; double[] arr4 = new double[] { 2.9, 5.8, 7.8 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr1, arr3)); System.out.println(Arrays.equals(arr1, arr4)); System.out.println(Arrays.equals(arr2, arr3)); System.out.println(Arrays.equals(arr2, arr4)); } }
Output
true false false false false
Advertisements