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 specified 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 specified 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
- AbstractList hashCode() method in Java with Examples
- Properties hashCode() method in Java with Examples
- ShortBuffer hashCode() Method in Java with Examples
- LocalDate hashCode() method in Java with Examples
- Float hashCode() method in Java with examples
- SortedMap hashCode() method in Java with Examples
- SimpleTimeZone hashCode() method in Java with Examples
- Short hashCode() method in Java with Examples
- Locale hashCode() Method in Java with Examples
- SortedSet hashCode() method in Java with Examples
- Constructor hashCode() method in Java with Examples
- NumberFormat hashCode() method in Java with Examples
- ChronoLocalDate 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.
Improved By : ManasChhabra2



