Open In App

SimpleTimeZone equals() method in Java with Examples

Last Updated : 02 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • true if the given obj is the same as this SimpleTimeZone object
  • false if the given obj is not same as this SimpleTimeZone object

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads