CopyPastehas never been so tasty!

Compare two Boolean arrays in java

by anonymous

  • 0
  • 0
  • 0

Compare two Boolean arrays in java

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

Add A Comment: