

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- Java Program to compare two Byte Arrays
- Java Program to compare Two Java short Arrays
- Java Program to compare Two Java float Arrays
- Java Program to compare two Java char Arrays
- Compare Two Java double arrays
- Compare Two Java long Arrays
- How to compare two arrays in Java?
- Compare Two Java int Arrays in Java
- Java Program to Compare Two Strings
- Java Program to compare two sets
- How do we compare two arrays in Java?
- How to compare two arrays in C#?
- Java Program to Concatenate Two Arrays
- Program to Compare two strings in Java
- Java Program to Compare two strings lexicographically
Advertisements