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:
// 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); } } |
Both ZoneIdsare equal: false
Program 2:
// 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); } } |
Both ZoneIdsare equal: true
References:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#equals(java.lang.Object)
Recommended Posts:
- ZoneId from() method in Java with Examples
- ZoneId getDisplayName() method in Java with Examples
- ZoneId getAvailableZoneIds() method in Java with Examples
- ZoneId ofOffset() method in Java with Examples
- ZoneId getId() method in Java with Examples
- ZoneId getRules() method in Java with Examples
- ZoneId hashCode() method in Java with Examples
- ZoneId toString() method in Java with Examples
- ZoneId systemDefault() method in Java with Examples
- ZoneId normalized() method in Java with Examples
- Set equals() method in Java with Examples
- Map equals() method in Java with Examples
- ChronoLocalDateTime equals() method in Java with Examples
- NumberFormat equals() method in Java with Examples
- SimpleDateFormat equals() Method in Java with Examples
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


