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:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
ZoneId ZoneId1
= ZoneId.of( "Europe/Paris" );
ZoneId ZoneId2
= ZoneId.of( "Asia/Calcutta" );
boolean response = ZoneId1.equals(ZoneId2);
System.out.println( "Both ZoneIds"
+ "are equal: " + response);
}
}
|
Output:
Both ZoneIdsare equal: false
Program 2:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
ZoneId ZoneId1
= ZoneId.of( "Asia/Calcutta" );
ZoneId ZoneId2
= ZoneId.of( "Asia/Calcutta" );
boolean response = ZoneId1.equals(ZoneId2);
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...