Boolean equals() method in Java with examples


The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object.

Syntax:

BooleanObject.equals(Object ob)

Parameter: It take a parameter ob of type Object as input which is the instance to be compared.

Return Type: The return type is boolean. It returns true if the specified Object ‘ob’ has same value as the ‘BooleanObject’, else it returns false.

Below are programs to illustrate the equals() method of Boolean class:

Program 1:

// Java code to implement // equals() method of Boolean class class GeeksforGeeks < // Driver method public static void main(String[] args) // Boolean object Boolean a = new Boolean( true ); // Boolean object Boolean b = new Boolean( true ); // compare method System.out.println(a + " comparing with " + b + " plain">+ a.equals(b)); Output:
true comparing with true = true

Program 2:

// Java code to implement // equals() method of Java class class GeeksforGeeks < // Driver method public static void main(String[] args) // Boolean object Boolean a = new Boolean( true ); // Boolean object Boolean b = new Boolean( false ); // compare method System.out.println(a + " comparing with " + b + " plain">+ a.equals(b)); Output:
true comparing with false = false

Program 3:

// Java code to implement // equals() method of Java class class GeeksforGeeks < // Driver method public static void main(String[] args) // Boolean object Boolean a = new Boolean( false ); // Boolean object Boolean b = new Boolean( true ); // compare method System.out.println(a + " comparing with " + b + " plain">+ a.equals(b)); Output:
false comparing with true = false
Like Article -->

Please Login to comment.

Similar Reads

Java Guava | Booleans.indexOf(boolean[] array, boolean target) method with Examples

Booleans.indexOf(boolean[] array, boolean target) method of Guava's Booleans Class accepts two parameters array and target. If the target exists within the array, the method returns the position of its first occurrence. If the target does not exist within the array, the method returns -1. Syntax: public static int indexOf(boolean[] array, boolean t

3 min read Java Guava | Booleans.indexOf(boolean[] array, boolean[] target) method with Examples

Booleans.indexOf(boolean[] array, boolean[] target) method of Guava's Booleans Class accepts two parameters array and target. If the target exists within the array, the method returns the start position of its first occurrence. If the target does not exist within the array, the method returns -1. Syntax: public static int indexOf(boolean[] array, b

2 min read Boolean booleanValue() method in Java with examples

The booleanValue() method of Boolean Class is a built in method in java which is used to return the primitive boolean value of instance which is used to call the method booleanValue(). Syntax BooleanObject.booleanValue() Return Value: It returns a primitive boolean value. Below are the examples to illustrate booleanValue() method: Program 1: class

1 min read Boolean parseBoolean() method in Java with examples

The parseBoolean() method of Boolean Class is a built in static method of the class java.lang.Boolean which is used to convert a given string to its boolean value. Syntax: Boolean.parseBoolean(String value) Parameters: It takes one parameter value of type string which contains the value which is to be converted to boolean. Return Value: It returns

2 min read Boolean compare() method in Java with Examples

The compare() method of Boolean class is a built in method in Java which is used to compare two boolean values. It is a static method, so it can be called without creating any object of the Boolean class i.e. directly using the class name. Syntax: Boolean.compare(boolean a, boolean b) Parameters: It takes two boolean values a and b in the parameter

2 min read Boolean compareTo() method in Java with examples

The compareTo() method of Boolean class is a built in method in Java which is used to compare the given Boolean instance with the current instance. Syntax: BooleanObject.compareTo(Boolean a) Parameters: It takes a Boolean value a as parameter which is to be compared with the current instance. Return Type: The return type of the function is int. It

2 min read Boolean hashCode() method in Java with examples

The hashCode() method of Boolean class is a built in method to return a int hashcode value corresponding to the Boolean object. Syntax BooleanObject.hashCode() Return Type: It returns a int hashcode value corresponding to the Boolean object. It returns 1231 if the Boolean object stores the value true. It returns 1237 if the Boolean object stores th

1 min read Boolean toString() method in Java with examples

The toString() method of Boolean class is a built in method to return the boolean value in string format. There are 2 overloads of toString() methods in Boolean class of Java: public static String toString(boolean value) Syntax Boolean.toString(boolean value) Parameter: It takes a boolean value as input which is to be converted to string. Return Ty

2 min read Matcher useTransparentBounds(boolean) method in Java with Examples

The useTransparentBounds(boolean) method of Matcher Class is used to set the transparent bounds of this matcher. By transparent bounds, it means that the matcher will be matched for the matching pattern beyond the region boundaries for getting a match, if the transparent bounds are set to true. This method returns a Matcher with the modified transp

2 min read Matcher useAnchoringBounds(boolean) method in Java with Examples

The useAnchoringBounds(boolean) method of Matcher Class is used to set the anchoring bounds of this matcher. By anchoring bounds, it means that the matcher will be matched for the anchors like ^ and $ for getting a match, if the anchoring bounds are set to true. This method returns a Matcher with the modified anchoring bounds. Syntax: public boolea

2 min read PrintStream println(boolean) method in Java with Examples

The println(boolean) method of PrintStream Class in Java is used to print the specified boolean value on the stream and then break the line. This boolean value is taken as a parameter. Syntax: public void println(boolean booleanValue) Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the

2 min read PrintStream print(boolean) method in Java with Examples

The print(boolean) method of PrintStream Class in Java is used to print the specified boolean value on the stream. This boolean value is taken as a parameter. Syntax: public void print(boolean booleanValue) Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the stream. Return Value: This m

2 min read TimeZone getDisplayName(boolean, int) Method in Java with Examples

The getDisplayName(boolean daylight, int style) method of TimeZone class in Java is used to get a particular name of this TimeZone that is easily understood by the user in the specified locale as passed by the user. The name is appropriate for presentation and display purpose. Syntax: public final String getDisplayName(boolean daylight, int style)

2 min read Class forName(String, boolean, ClassLoader) method in Java with Examples

The forName(String, boolean, ClassLoader) method of java.lang.Class class is used to get the instance of this Class with the specified class name, using the specified class loader. The class is initialized only if the initialize parameter is true and if it has not been initialized earlier.Syntax: public static Class<T> forName(String classNam

2 min read ChoiceFormat nextDouble(double, boolean) method in Java with Examples

The nextDouble(double, boolean) method of java.text.ChoiceFormat class is used to get the double value just greater than the passed double value if passed Boolean value is true or it will return the double value just lesser than the passed double value if passed Boolean value is false. Syntax: public static double nextDouble(double d, boolean posit

2 min read PrintWriter print(boolean) method in Java with Examples

The print(boolean) method of PrintWriter Class in Java is used to print the specified boolean value on the stream. This boolean value is taken as a parameter. Syntax: public void print(boolean booleanValue) Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the stream. Return Value: This m

2 min read PrintWriter println(boolean) method in Java with Examples

The println(boolean) method of PrintWriter Class in Java is used to print the specified boolean value on the stream and then break the line. This boolean value is taken as a parameter. Syntax: public void println(boolean booleanValue) Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the

2 min read Java.util.Arrays.equals() in Java with Examples

Today we are going to discuss the simplest way to check whether two arrays are equal or not. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements in the same order. Also, two arra

4 min read Java Long equals() method with Examples

The java.lang.Long.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object. It returns false if both the objects are not same. In all other cases, compareTo method should be preferred. S

3 min read Character.equals() method in Java with examples

The java.lang.Character.equals() is a function in Java which compares this object against the specified object. If the argument is not null then the result is true and is a Character object that represents the same char value as this object. Syntax: public boolean equals(Object obj) Parameters: The function accepts a single parameter obj which spec

2 min read Double.equals() Method in Java with Examples

The java.lang.Double.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. It returns false if both the objects are not same. In all other cases, compareTo method should be prefer

2 min read Java 8 Clock equals() Method with Examples

Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8.The equals() method of java.time.Clock class checks if two Clock objects are equal or not. If clocks are equal then it returns true, else it returns false. This equals method of clock class overrides this Object.equals(java.lang

3 min read FloatBuffer equals() method in Java with Examples

The equals() method of java.nio.FloatBuffer Class is used to check whether or not the given buffer is equal to another object. Two float buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, considered independently of their starting position

4 min read ShortBuffer equals() method in Java with Examples

The equals() method of java.nio.ShortBuffer Class is used to check whether or not the given buffer is equal to another object. Two short buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, considered independently of their starting position

3 min read DoubleBuffer equals() method in Java with Examples

The equals() method of java.nio.DoubleBuffer Class is used to check whether or not the given buffer is equal to another object. Two double buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, considered independently of their starting positi

3 min read ByteBuffer equals() method in Java with Examples

The equals() method of java.nio.ByteBuffer class is used to check whether or not the given buffer is equal to another object. Two byte buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, considered independently of their starting positions,

3 min read Byte equals() method in Java with examples

The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method. Syntax ByteObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance of the Byte object calling the equals method. Ret

2 min read Short equals() method in Java with Examples

The equals() method of Short class is a built in method in Java which is used to compare the equality given Object with the instance of Short invoking the equals() method. Syntax ShortObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance of the Short object calling the equals method.

2 min read LocalDateTime equals() method in Java with Examples

The equals() method of LocalDateTime class in Java checks if this date-time is equal to another date-time. This other date-time is passed as the parameter. This method returns a boolean value showing the same. Syntax: public boolean equals(Object date2) Parameter: This method accepts a parameter date2 which checks if this date-time is equal to anot

2 min read AbstractList equals() method in Java with Examples

The equals() method of java.util.AbstractList class is used to compare the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.eq