Java Clock Class | hashCode() Method with Example

Clock Class hashCode() method: Here, we are going to learn about the hashCode() method of Clock Class with its syntax and example.
Submitted by Preeti Jain, on May 13, 2020

Clock Class hashCode() method

  • hashCode() method is available in java.time package.
  • hashCode() method is used to get the hash code value of this Clock.
  • hashCode() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • hashCode() method does not throw an exception at the time of returning hash code.

Syntax:

    public int hashCode();

Parameter(s):

  • None

Return value:

The return type of this method is int, it retrieves this Clock hash code value.

Example:

// Java program to demonstrate the example 
// of int hashCode() method of Clock

import java.time.*;

public class HashCodeOfClock {
    public static void main(String args[]) {
        // Instantiates two ZoneId for Accra and Asmara
        ZoneId zone_1 = ZoneId.of("Africa/Accra");
        ZoneId zone_2 = ZoneId.of("Africa/Asmara");

        // Initialize two Clock objects  
        Clock cl1 = Clock.system(zone_1);
        Clock cl2 = Clock.system(zone_2);

        // returns the hash code value of this Clock cl1
        int cl_hc = cl1.hashCode();

        // Display cl1 hash code
        System.out.println("cl1.hashCode(): " + cl_hc);

        // returns the hash code value of this Clock cl2
        cl_hc = cl2.hashCode();

        // Display cl2 hash code
        System.out.println("cl2.hashCode(): " + cl_hc);
    }
}

Output

cl1.hashCode(): 1799826076
cl2.hashCode(): -24907989



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.