Java 8 Clock hashCode() method

Java 8ProgrammingObject Oriented Programming

The hash code for a clock object can be obtained using the method hashCode() in the Clock Class in Java. This method requires no parameters and it returns the acceptable hash code for a clock object.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      Clock c = Clock.systemDefaultZone();
      int hashCode = c.hashCode();
      System.out.println("The clock is: " + c);
      System.out.println("The hash code is: " + hashCode);
   }
}

Output

The clock is: SystemClock[Etc/UTC]
The hash code is: 227139178

Now let us understand the above program.

The hash code for the specified clock object is obtained using the method hashCode() and then this value is displayed. A code snippet that demonstrates this is as follows −

Clock c = Clock.systemDefaultZone();
int hashCode = c.hashCode();
System.out.println("The clock is: " + c);
System.out.println("The hash code is: " + hashCode);
raja
Published on 13-Mar-2019 15:43:18
Advertisements