MathContext equals(Object) in Java

equals(Object): This method is available in java.math.MathContext class of Java.

Syntax:

boolean java.math.MathContext.equals(Object x)

This method takes one argument of type Object(like MathContext, Integer, etc..) as its parameters. This method compares this MathContext with the specified Object for equality.

Parameters: One parameter is required for this method.

x: Object to which this MathContext is to be compared.

Returns: true if and only if the specified Object is a MathContext object which has exactly the same settings as this object.

Exceptions: NA

Approach

Java

import java.math.MathContext;

public class MathContextequals {
    public static void main(String[] args) {

        MathContext mc = MathContext.DECIMAL128;

        Object x = MathContext.DECIMAL128;
        System.out.println(mc.equals(x));
    }
}

Output:

true


Some other methods of MathContext class

MathContext.DECIMAL128A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and rounding mode of HALF_EVEN, the IEEE 754R default.

MathContext.DECIMAL32A MathContext object with a precision setting matching the IEEE 754R Decimal32 format, 7 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.

MathContext.DECIMAL64A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.

equals(Object)This method compares this MathContext with the specified Object for equality.

getPrecision()This method returns the precision setting. This value is always non-negative.

getRoundingMode()This method returns the roundingMode setting.

hashCode()This method returns the hash code for this MathContext.

toString()This method returns the string representation of this MathContext.

MathContext.UNLIMITEDA MathContext object whose settings have the values required for unlimited precision arithmetic.

MathContext(int)This method constructs a new MathContext with the specified precision and the HALF_UP rounding mode.

MathContext(String)This method constructs a new MathContext from a string. The string must be in the same format as that produced by the toString method.

MathContext(int, RoundingMode)This method constructs a new MathContext with a specified precision and rounding mode.

No comments:

Post a Comment