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:

  • 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

Result of comparison is : false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

Result of comparison is : true



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.