Java 8 Clock hashCode() method



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);
Updated on: 2019-07-30T22:30:25+05:30

278 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements