ZoneId equals() method in Java with Examples

equals() method of the ZoneId class used to compare this ZoneId to the ZoneId object passed as parameter. The value to be returned by this method is determined as follows:

  • if both ZoneId are equal, then true is returned
  • if both ZoneId are not equal, then false is returned.

Syntax:

public boolean equals(Object obj)

Parameters: This method accepts a single parameter obj which represents the object to compare with this ZoneId, It can’t be null.



Return value: This method returns true if both ZoneId are equal else false.

Below programs illustrate the equals() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ZoneId.equals() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create two diff ZoneId objects
        ZoneId ZoneId1
            = ZoneId.of("Europe/Paris");
  
        ZoneId ZoneId2
            = ZoneId.of("Asia/Calcutta");
  
        // apply equals() method to check
        // whether both ZoneIds are equal or not
        boolean response = ZoneId1.equals(ZoneId2);
  
        // print result
        System.out.println("Both ZoneIds"
                           + "are equal: " + response);
    }
}

chevron_right


Output:

Both ZoneIdsare equal: false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ZoneId.equals() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create two diff ZoneId objects
        ZoneId ZoneId1
            = ZoneId.of("Asia/Calcutta");
  
        ZoneId ZoneId2
            = ZoneId.of("Asia/Calcutta");
  
        // apply equals() method to check
        // whether both ZoneIds are equal or not
        boolean response = ZoneId1.equals(ZoneId2);
  
        // print result
        System.out.println("Both ZoneIds"
                           + "are equal: " + response);
    }
}

chevron_right


Output:

Both ZoneIdsare equal: true

References:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#equals(java.lang.Object)



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

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.



Improved By : Akanksha_Rai