Date hashCode() method in Java with Examples
The hashCode() method of Java Date class returns a value which is a hash code for this object.
Syntax:
public int hashCode()
Parameters: The function does not accept any parameter.
Return Value: It returns a hashCode value for this object.
Exception: The function does not throws any exception.
Program below demonstrates the above mentioned function:
// Java code to demonstrate // hashCode() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c1 = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 11); // set Date c1.set(Calendar.DATE, 05); // set Year c1.set(Calendar.YEAR, 1996); // creating a date object with specifed time. Date dateOne = c1.getTime(); System.out.println("Date: " + dateOne); // Prints hash Code System.out.println("HashCode: " + dateOne.hashCode()); } } |
chevron_right
filter_none
Output:
Date: Thu Dec 05 08:22:04 UTC 1996 HashCode: -629399711
// Java code to demonstrate // hashCode() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c1 = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 11); // set Date c1.set(Calendar.DATE, 21); // set Year c1.set(Calendar.YEAR, 1999); // creating a date object with specifed time. Date dateOne = c1.getTime(); System.out.println("Date: " + dateOne); // Prints hash Code System.out.println("HashCode: " + dateOne.hashCode()); } } |
chevron_right
filter_none
Output:
Date: Tue Dec 21 08:22:09 UTC 1999 HashCode: 871724355
Recommended Posts:
- Map hashCode() Method in Java with Examples
- Set hashCode() method in Java with Examples
- Double hashCode() method in Java with examples
- OptionalLong hashCode() method in Java with examples
- Duration hashCode() method in Java with Examples
- Calendar hashCode() Method in Java with Examples
- DecimalFormatSymbols hashCode() method in Java with Examples
- Locale hashCode() Method in Java with Examples
- LocalTime hashCode() method in Java with Examples
- NumberFormat hashCode() method in Java with Examples
- ByteBuffer hashCode() method in Java with Examples
- ChronoLocalDate hashCode() method in Java with Examples
- List hashCode() Method in Java with Examples
- ChronoLocalDateTime hashCode() method in Java with Examples
- LocalDateTime hashCode() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



