Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
DateFormat hashCode() method in Java with Examples
Next article icon

Duration hashCode() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The hashCode() method of Duration Class in java.time package is used to get the hashCode value of this duration.

Syntax:

  public int hashCode()  

Parameters: This method do not accepts any parameter.

Return Value: This method returns an int value which is the hashCode value of this duration.

Below examples illustrate the Duration.hashCode() method:

Example 1:




// Java code to illustrate hashCode() method
  
import java.time.Duration;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Duration using parse() method
        Duration duration = Duration.parse("P2DT3H4M");
  
        // Get the hashCode value
        // using hashCode() method
        System.out.println(duration.hashCode());
    }
}
 
 
Output:
  183840  

Example 2:




// Java code to illustrate hashCode() method
  
import java.time.Duration;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Duration using ofHours() method
        Duration duration = Duration.ofHours(5);
  
        // Get the hashCode value
        // using hashCode() method
        System.out.println(duration.hashCode());
    }
}
 
 
Output:
  18000  

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#hashCode–



Next Article
DateFormat hashCode() method in Java with Examples

C

code_r
Improve
Article Tags :
  • Java
  • Java-Duration
  • Java-Functions
  • Java-time package
Practice Tags :
  • Java

Similar Reads

  • 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. Progr
    2 min read
  • Duration getSeconds() method in Java with Examples
    The getSeconds() method of Duration Class in java.time package is used to get the second value of this duration. Syntax: public long getSeconds() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value of the seconds of this duration. Below examples illus
    1 min read
  • Double hashCode() method in Java with examples
    The hashCode() method of Double class is a built-in method use to return the hashcode value of this Double object. Syntax: DoubleObject.hashCode() Parameters: It takes no parameters. Return Type: It returns an int value. The value returned is (int)(v^(v>>>32)) where v is a long variable equ
    1 min read
  • Byte hashCode() method in Java with examples
    The hashCode() method of Byte class is a built in method in Java which is used to return the hash code of the ByteObject. Note: The hashCode() returns the same value as intValue(). Syntax ByteObject.hashCode() Return Value: It return an int value which represents the hashcode of the specified Byte o
    2 min read
  • DateFormat hashCode() method in Java with Examples
    The hashCode() Method of DateFormat class is used to return the hash code value of this DateFormat object. The hash code is of integer type. Syntax: public int hashCode() Parameters: The method does not take any parameters. Return Value: The method returns the hash code value of this DateFormat obje
    2 min read
  • Duration getNano() method in Java with Examples
    The getNano() method of Duration Class in java.time package is used to get the nanos value of this duration. Syntax: public long getNano() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value of the nanos of this duration. Below examples illustrate the
    1 min read
  • Class hashCode() method in Java with Examples
    The hashCode() method of java.lang.Class class is used to get the hashCode representation of this entity. This method returns an integer value which is the hashCode. Syntax: public int hashCode() Parameter: This method does not accept any parameter. Return Value: This method returns an integer value
    1 min read
  • Charset hashCode() method in Java with Examples
    The hashCode() method is a built-in method of the java.nio.charset returns the computed hashcode of any given charset. Syntax: public final int hashCode() Parameters: The function does not accepts any parameter. Return Value: The function returns the computed hashcode for the charset. Below is the i
    1 min read
  • AbstractList hashCode() method in Java with Examples
    The hashCode() method of java.util.AbstractList class is used to return the hash code value for this list. Syntax: public int hashCode() Returns Value: This method returns the hash code value for this list. Below are the examples to illustrate the hashCode() method. Example 1: // Java program to dem
    2 min read
  • Collator hashCode() method in Java with Example
    The hashCode() method of java.text.Collator class is used to get the hashCode for this Collator object. Syntax: public abstract int hashCode() Parameter: This method does not accept any parameter.Return Value: This method returns hash code value in integer format. Below are the examples to illustrat
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences