w3resource

Java Date.hashCode()Method

public int hashCode()

The hashCode() method returns a hash code value for this object.
The result is the exclusive OR of the two halves of the primitive long value returned by the hashCode() method.
That is, the hash code is the value of the expression : (int)(this.getTime()^(this.getTime() >>> 32));

Package: java.util

Java Platform: Java SE 8

Syntax:

public int hashCode()

Return Value:
a hash code value for this object.

Return Value Type: int

Example: Java Date.hashCode() Method

import java.util.Date;
public class Main {
   public static void main(String[] args) {

      // create a date
      Date date = new Date(2017, 11, 10);

      // display the date
      System.out.println("Date: " + date.toString());

      // Print the said date using hash code and print it
      int i = date.hashCode();
      System.out.println("A hash code of the said date: " + i);
   }
}
 

Output:

Date: Mon Dec 10 00:00:00 UTC 3917
A hash code of the said date: 1436073960

Java Code Editor:

Previous:getTime Method
Next:setTime Method



Follow us on Facebook and Twitter for latest update.