DecimalFormat equals() method in Java
The equals() method is a built-in method of the java.text.DecimalFormat class 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:
// Java program to illustrate the // equals() method import java.text.DecimalFormat; import java.util.Currency; import java.util.Locale; public class Main { public static void main(String[] args) { // Get the Currency Instance DecimalFormat dF1 = new DecimalFormat(); dF1.getCurrencyInstance(); // Get the Currency Instance DecimalFormat dF2 = new DecimalFormat(); dF2.getCurrencyInstance(); // Check if equal or not if (dF1.equals(dF2)) System.out.println( "Yes both are equal" ); else System.out.println( "Yes both are not equal" ); } } |
Yes both are equal
Program 2:
// Java program to illustrate the // equals() method import java.text.DecimalFormat; import java.util.Currency; import java.util.Locale; public class Main { public static void main(String[] args) { // Get the Currency Instance DecimalFormat dF1 = new DecimalFormat(); dF1.getCurrencyInstance(); // Get Instance DecimalFormat dF2 = new DecimalFormat(); dF2.setCurrency(Currency.getInstance(Locale.GERMANY)); // Check if equal or not if (dF1.equals(dF2)) System.out.println( "Yes both are equal" ); else System.out.println( "Yes both are not equal" ); } } |
Yes both are not equal
Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#clone()
Recommended Posts:
- DecimalFormat getDecimalFormatSymbols() method in Java
- DecimalFormat setNegativeSuffix() method in Java
- DecimalFormat setPositivePrefix() method in Java
- DecimalFormat setPositiveSuffix() method in Java
- DecimalFormat getMaximumFractionDigits() method in Java
- DecimalFormat getCurrency() method in Java
- DecimalFormat setMinimumIntegerDigits() method in Java
- DecimalFormat setMinimumFractionDigits() method in Java
- DecimalFormat hashCode() method in Java
- DecimalFormat setNegativePrefix() method in Java
- DecimalFormat isParseBigDecimal() method in Java
- DecimalFormat getGroupingSize() method in Java
- DecimalFormat getPositiveSuffix() method in Java
- DecimalFormat getPositivePrefix() method in Java
- DecimalFormat getNegativeSuffix() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.