Java SimpleTimeZone equals() Method



Description

The Java SimpleTimeZone equals(Object obj) method is used to compare the equality of two SimpleTimeZone objects.

Declaration

Following is the declaration for java.util.SimpleTimeZone.equals() method.

public boolean equals(Object obj)

Parameters

obj − This is the SimpleTimeZone object to be compared with.

Return Value

The method call returns true if the given obj is the same as this SimpleTimeZone object; false otherwise.

Exception

NA

Comparing Two Same SimpleTimeZone of India timezone for Equality Example

The following example shows the usage of Java SimpleTimeZone equals() method to check equality of two SimpleTimeZone objects. We've created two SimpleTimeZone objects using India then compared them for equality using equals() method and result is printed.

package com.tutorialspoint;

import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create two simple time zone objects 
      SimpleTimeZone stobj1 = new SimpleTimeZone(720,"India");
      SimpleTimeZone stobj2 = new SimpleTimeZone(720,"India");

      // compare two objects      
      System.out.println("Comparison result: " + stobj1.equals(stobj2));
   }      
}

Output

Let us compile and run the above program, this will produce the following result.

Comparison result: true

Comparing Two Same SimpleTimeZone objects of America for Equality Example

The following example shows the usage of Java SimpleTimeZone equals() method to check equality of two SimpleTimeZone objects. We've created two SimpleTimeZone objects using America/Los_Angeles then compared them for equality using equals() method and result is printed.

package com.tutorialspoint;

import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create two simple time zone objects 
      SimpleTimeZone stobj1 = new SimpleTimeZone(720,"America/Los_Angeles");
      SimpleTimeZone stobj2 = new SimpleTimeZone(720,"America/Los_Angeles");

      // compare two objects      
      System.out.println("Comparison result: " + stobj1.equals(stobj2));
   }      
}

Output

Let us compile and run the above program, this will produce the following result.

Comparison result: true

Comparing Two Same SimpleTimeZone objects of Europe Timezone for Equality Example

The following example shows the usage of Java SimpleTimeZone equals() method to check equality of two SimpleTimeZone objects. We've created two SimpleTimeZone objects using Europe/Paris then compared them for equality using equals() method and result is printed.

package com.tutorialspoint;

import java.util.SimpleTimeZone;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ) {
      
      // create two simple time zone objects 
      SimpleTimeZone stobj1 = new SimpleTimeZone(720,"Europe/Paris");
      SimpleTimeZone stobj2 = new SimpleTimeZone(720,"Europe/Paris");

      // compare two objects      
      System.out.println("Comparison result: " + stobj1.equals(stobj2));
   }      
}

Output

Let us compile and run the above program, this will produce the following result.

Comparison result: true
java_util_simpletimezone.htm
Advertisements