 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to compare two Boolean Arrays
Use Arrays.equals() method to compare two Boolean Arrays. Let us first create some arrays to be compared. For using this method, you need to import the following package −
import java.util.Arrays;
We have 4 arrays and value “true” and “false” are assigned to them.
boolean[] myArr1 = new boolean[] { true, false, true, true, true }; boolean[] myArr2 = new boolean[] { true, false, true, true , true }; boolean[] myArr3 = new boolean[] { false, false, true, true, true }; boolean[] myArr4 = new boolean[] { true, false, false, true , false }; Now, let us compare Boolean arrays 1 and 2.
Arrays.equals(myArr1, myArr2);
In the same way, we can compare other arrays as well.
Let us see the complete example to compare Boolean Arrays in Java.
Example
import java.util.Arrays; public class Demo {    public static void main(String[] args) {       boolean[] myArr1 = new boolean[] { true, false, true, true, true };       boolean[] myArr2 = new boolean[] { true, false, true, true , true };       boolean[] myArr3 = new boolean[] { false, false, true, true, true };       boolean[] myArr4 = new boolean[] { true, false, false, true , false };       System.out.println(Arrays.equals(myArr1, myArr2));       System.out.println(Arrays.equals(myArr2, myArr3));       System.out.println(Arrays.equals(myArr3, myArr4));       System.out.println(Arrays.equals(myArr1, myArr4));    } }  Output
true false false false
Advertisements
 