Java SimpleTimeZone.equals(Object obj) method example

 Posted On  | Pooja Lakkihal 

In this tutorial, You will learn how to check if the two zones are equal or not . Java SimpleTimeZone.equals(Object obj) method returns true if the two zones are same as this SimpleTimeZone object.

Compares the equality of two SimpleTimeZone objects.

syntax

public boolean equals(Object obj)

Parameters

obj - The SimpleTimeZone object to be compared with.

Returns

true if the given obj is the same as this SimpleTimeZone object; false otherwise.

Java SimpleTimeZone equals(Object obj) example

  • new SimpleTimeZone(300, "INDIA"); It will construct a SimpleTimeZone with the given base time zone.
  • simpleTimeZone1.equals(simpleTimeZone2); It will compare the equality of two objects. In first case it returns true and in second case it returned false value.
package com.technicalkeeda;

import java.util.SimpleTimeZone;

public class App {

    public static void main(String[] args) {

        SimpleTimeZone simpleTimeZone1 = new SimpleTimeZone(300, "INDIA");
        SimpleTimeZone simpleTimeZone2 = new SimpleTimeZone(300, "INDIA");
        SimpleTimeZone simpleTimeZone3 = new SimpleTimeZone(400, "US");

        boolean equals1 = simpleTimeZone1.equals(simpleTimeZone2);
        boolean equals2 = simpleTimeZone1.equals(simpleTimeZone3);

        System.out.println("Is simpleTimeZone1 equals to simpleTimeZone2 ? " + equals1);
        System.out.println("Is simpleTimeZone1 equals to simpleTimeZone3 ? " + equals2);

    }
}

output

Is simpleTimeZone1 equals to simpleTimeZone2 ? true
Is simpleTimeZone1 equals to simpleTimeZone3 ? false


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0439 seconds.