NumberFormat equals() method in Java with Examples
Last Updated :
01 Apr, 2019
The equals() method is a built-in method of the java.text.NumberFormat accepts an argument which is an object and returns true if this argument object is same as the object, else it returns false.
Syntax:
public boolean equals(Object arg)
Parameters: The function accepts a single mandatory parameter arg which specifies the object which is to be compared with.
Return Value: The function returns a boolean value. It returns true if both the objects are same else it returns false.
Below is the implementation of the above function:
Program 1:
import java.text.NumberFormat;
public class Main {
public static void main(String[] args)
throws Exception
{
NumberFormat nF1
= NumberFormat
.getCurrencyInstance();
NumberFormat nF2
= NumberFormat
.getCurrencyInstance();
if (nF1.equals(nF2))
System.out.println( "Yes both are equal" );
else
System.out.println( "Yes both are not equal" );
}
}
|
Output:
Yes both are equal
Program 2:
import java.text.NumberFormat;
public class Main {
public static void main(String[] args)
throws Exception
{
NumberFormat nF1
= NumberFormat
.getCurrencyInstance();
NumberFormat nF2
= NumberFormat
.getInstance();
if (nF1.equals(nF2))
System.out.println( "Yes both are equal" );
else
System.out.println( "both are not equal" );
}
}
|
Output:
both are not equal
Reference: https://docs.oracle.com/javase/10/docs/api/java/text/NumberFormat.html#equals(java.lang.Object)
Share your thoughts in the comments
Please Login to comment...