Skip to content
Related Articles

Related Articles

DecimalStyle equals() method in Java with Example

Improve Article
Save Article
  • Last Updated : 26 Aug, 2019
Improve Article
Save Article

The equals() method of java.time.format.DecimalStyle class in Java is used to check for equality of this DecimalStyle with the specified DecimalStyle. This method takes a DecimalStyle instance and compares it with this DecimalStyle and returns a boolean value representing the same.

Syntax:

public boolean equals(Object obj)

Parameter: This method accepts a parameter obj which is the DecimalStyle to be checked for equality with this DecimalStyle.

Return Value: This method returns an boolean which tells if this DecimalStyle is equal to the specified Object.

Exception: This method do not throw any Exception.

Program:




// Java program to demonstrate
// the above method
  
import java.time.format.*;
import java.util.*;
  
public class DecimalStyleDemo {
    public static void main(String[] args)
    {
  
        DecimalStyle ds1
            = DecimalStyle.STANDARD;
  
        DecimalStyle ds2
            = DecimalStyle.of(
                new Locale("ENGLISH"));
  
        DecimalStyle ds3 = null;
  
        System.out.println("Comparing DS 1 and DS 2: "
                           + ds1.equals(ds2));
  
        System.out.println("Comparing DS 2 and DS 3: "
                           + ds2.equals(ds3));
  
        System.out.println("Comparing DS 1 and DS 3: "
                           + ds1.equals(ds3));
    }
}

Output:

Comparing DS 1 and DS 2: true
Comparing DS 2 and DS 3: false
Comparing DS 1 and DS 3: false

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/format/DecimalStyle.html#equals(java.lang.Object)

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!