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); } } |
Output:
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); } } |
Output:
Both ZoneIdsare equal: true
References:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#equals(java.lang.Object)
Contact Us