Skip to content
Related Articles

Related Articles

Improve Article

ZoneId equals() method in Java with Examples

  • Last Updated : 30 Jul, 2019

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)

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :