DecimalFormatSymbols equals() method in Java with Examples
The equals()
method in the DecimalFormatSymbols
class of Java is used to compare two DecimalFormatSymbols
objects for equality. It returns true
if the two objects are equal, i.e., if they have the same set of symbols for decimal separator, grouping separator, percent sign, and so on.
Syntax:
public boolean equals(Object obj)
Parameters:
- obj
: the object to compare with the current object.
Returns:
- true
if the two objects are equal, false
otherwise.
Example 1:
DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(Locale.US);
DecimalFormatSymbols dfs2 = new DecimalFormatSymbols(Locale.US);
boolean result = dfs1.equals(dfs2);
System.out.println(result); // Output: true
In this example, we create two DecimalFormatSymbols
objects with the same locale (US) and compare them using the equals()
method. Since they have the same set of symbols, the method returns true
.
Example 2:
DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(Locale.US);
DecimalFormatSymbols dfs2 = new DecimalFormatSymbols(Locale.FRANCE);
boolean result = dfs1.equals(dfs2);
System.out.println(result); // Output: false
In this example, we create two DecimalFormatSymbols
objects with different locales (US and France) and compare them using the equals()
method. Since they have different sets of symbols, the method returns false
.
Note: The equals()
method is inherited from the Object
class, so it compares the objects based on their memory addresses by default. However, the DecimalFormatSymbols
class overrides this method to compare the objects based on their symbol sets.