RoudingMode equals(Object) in Java

quals(Object): This method is available in java.lang.Enum class of Java.

Syntax:

boolean java.lang.Enum.equals(Object other)

This method takes one argument of type Object(RoundingMode, Integer, etc..). This method returns true if the specified object is equal to this enum constant.

Parameters: One parameter is required for this method.

other: the object to be compared for equality with this object.

Returns: true if the specified object is equal to this enum constant.

Exceptions: NA

Approach

Java

import java.math.RoundingMode;

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

        RoundingMode rm = RoundingMode.CEILING;

        RoundingMode other = RoundingMode.CEILING;
        System.out.println(rm.equals(other));
    }
}

Output:

true


Some other methods of RoundingMode

RoundingMode.CEILINGRounding mode to round towards positive infinity.

compareTo()This method compares this enum with the specified object for order.

describeConstable()This method returns an enum descriptor Enum Desc for this instance if one can be constructed, or an empty Optional if one cannot be.

RoundingMode.DOWNRounding mode to round towards zero.

equals(Object) This method returns true if the specified object is equal to this enum constant.

RoundingMode.FLOORRounding mode to round towards negative infinity.

getClass()This method returns the runtime class of this Object.

getDeclaringClass()This method returns the Class object corresponding to this enum constant's enum type.

RoundingMode.HALF_DOWNRounding mode to round towards "nearest neighbor"unless both neighbors are equidistant, in which case round down.

RoundingMode.HALF_EVENRounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

RoundingMode.HALF_UPRounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

hashCode()This method returns a hash code for this enum constant.

name()This method returns the name of this enum constant, exactly as declared in its enum declaration.

ordinal()This method returns the ordinal of this enumeration constant.

toString()This method returns the name of this enum constant, as contained in the declaration.

RoundingMode.UNNECESSARYRounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.

RoundingMode.UPRounding mode to round away from zero.

RoundingMode.valueOf(int)This method returns the RoundingMode object corresponding to a legacy integer rounding mode constant in BigDecimal.

RoundingMode.valueOf(String)his method returns the RoundingMode object corresponding to a legacy String rounding mode constant in BigDecimal.

RoundingMode.values()This method returns the RoundingMode array (or list of RoundingMode constants).

No comments:

Post a Comment