Open In App

SimpleTimeZone equals() method in Java with Examples

The equals() method of SimpleTimeZone class is used to compare the equality of two SimpleTimeZone objects.

Syntax:



public boolean equals(Object obj)

Parameters: The function accepts a single parameter obj which is a SimpleTimeZone object to be compared with.

Return Value: The method returns two values:



Exception: The function does not throws any exception.

Program below demonstrates the above mentioned function:

Program 1:




// program to demonstrate the
// function java.util.date.equals()
import java.util.SimpleTimeZone;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create first simple time zone object
        SimpleTimeZone obj1
            = new SimpleTimeZone(520, "India");
  
        // create second simple time zone object
        SimpleTimeZone obj2
            = new SimpleTimeZone(780, "India");
  
        // compare two objects and print the result
        System.out.println("Result of comparison is : "
                           + obj1.equals(obj2));
    }
}

Output:
Result of comparison is : false

Program 2:




// program to demonstrate the
// function java.util.date.equals()
import java.util.SimpleTimeZone;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create first simple time zone object
        SimpleTimeZone obj1
            = new SimpleTimeZone(520, "India");
  
        // create second simple time zone object
        SimpleTimeZone obj2
            = new SimpleTimeZone(520, "India");
  
        // compare two objects and print the result
        System.out.println("Result of comparison is : "
                           + obj1.equals(obj2));
    }
}

Output:
Result of comparison is : true

Article Tags :