Coding Villa

Compare two Boolean arrays in java

Author : Jal Pari

Share with Friends
Views : 749
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this article you will learn how to compare two Boolean arrays using Arrays class in java.


Advertisements


 

 

 

Boolean Data Type:

 

In Boolean data type there are only two conditions that is either true or false, yes or no, or on or off.  It is Built- in data type in Java.  

 

Equal method of arrays class:

 

The equals () method of java.lang.Object acts the same as the == operator. The basic function of the equals () method is that it tests for equality so most classes will override equals () that will compare what to return true or false.

 

You have to take 2 Boolean data types x1 and x2 then compare them according to the equal method of the array.

 

Here is sample code to compare two Boolean arrays:

 

 

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {

    boolean[ ] x1 = new boolean[] { true, false, true };

    boolean[ ] x2 = new boolean[] { true, false, true };

    System.out.println(Arrays.equals(x1, x2));

  }

}

 

 

This simple article tells that how we can compare two Boolean arrays using Arrays class in java

 

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook