- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Instant hashCode() method in Java
The hash code for a particular Instant object can be obtained using the hashCode() method in the Instant class in Java. This method requires no parameters and it returns the hash code for the Instant object.
A program that demonstrates this is given as follows
Example
import java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); System.out.println("The current instant is: " + i); int hashCode = i.hashCode(); System.out.println("The Hash Code value for the instant is: " + hashCode); } }
Output
The current instant is: 2019-02-13T12:05:21.488Z The Hash Code value for the instant is: 668255745
Now let us understand the above program.
First the current instant is displayed. Then the hash code for that Instant is obtained using the hashCode() method and that is also displayed. A code snippet that demonstrates this is as follows:
Instant i = Instant.now(); System.out.println("The current instant is: " + i); int hashCode = i.hashCode(); System.out.println("The Hash Code value for the instant is: " + hashCode);
- Related Articles
- Duration hashCode() method in Java
- LocalDate hashCode() method in Java
- LocalTime hashCode() method in Java
- MonthDay hashCode() method in Java
- LocalDateTime hashCode() method in Java
- Period hashCode() method in Java
- The hashCode() method of CopyOnWriteArrayList method in Java
- Java 8 Clock hashCode() method
- Instant minusMillis() method in Java
- Instant minusNanos() method in Java
- Instant until() Method in Java
- Instant plus() method in Java
- Instant minus() method in Java
- Instant isSupported() method in Java
- Instant truncatedTo() method in Java

Advertisements