Path hashCode() method in Java with Examples Last Updated : 16 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The Java Path interface was added to Java NIO in Java 7. hashCode() method of java.nio.file.Path used to return a hash code for this path after computing hashcode. The hashcode is always the same if the object doesn’t change. Hashcode is a unique code generated by the JVM at time of object creation. It can be used to perform some operation on hashing related algorithm like a hashtable, hashmap etc. An object can also be searched with its unique code (hashcode). Syntax: int hashCode() Parameters: This method accepts nothing. Return value: This method returns the hash-code value for this path. Below programs illustrate hashCode() method: Program 1: Java // Java program to demonstrate // java.nio.file.Path.hashCode() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Path Path path = Paths.get("D:/workspace/AmanCV.docx"); // call hashCode() to get hashCode int hashCode = path.hashCode(); // print hashCode System.out.println("Hash Code: " + hashCode); } } Output: Hash Code: 1600751599 Program 2: Java // Java program to demonstrate // java.nio.file.Path.hashCode() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Path Path path = Paths.get("D:/Resume.pdf"); // call hashCode() to get hashCode int hashCode = path.hashCode(); // print hashCode System.out.println("Hash Code: " + hashCode); } } Output: Hash Code: -996777206 References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#hashCode() Comment More infoAdvertise with us Next Article Path hashCode() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Path java.nio.file package Practice Tags : Java Similar Reads Short hashCode() method in Java with Examples The hashCode() method of Short class is a built in method in Java which is used to return the hash code of the ShortObject. Note: The hashCode() returns the same value as intValue(). Syntax ShortObject.hashCode() Return Value: It return an int value which represents the hashcode of the specified Sho 2 min read Package hashCode() method in Java with Examples The hashCode() method of java.lang.Package class is used to get the hashCode value of this package instance. The method returns the hashCode value as an integer value.Syntax: public int hashCode() Parameter: This method does not accepts any parameter.Return Value: This method returns the hashCode va 2 min read Period hashCode() method in Java with Examples The hashCode() method of Period class in Java is used to get the generated hashCode for this period. Syntax: public int hashCode() Parameters: This method does not accepts any parameter. Return Value: This method returns the hashCode generated for the given period. Below programs illustrate the hash 2 min read Optional hashCode() method in Java with examples The hashCode() method of java.util.Optional class in Java is used to get the hashCode value of this Optional instance. If there is no value present in this Optional instance, then this method returns 0. Syntax: public int hashCode() Parameter: This method do not accepts any parameter. Return Value: 1 min read MonthDay hashCode() method in Java with Examples hashCode() method of the MonthDay class used to get hashCode for this MonthDay. The hashcode is always the same if the object doesnât change. Hashcode is a unique code generated by the JVM at time of object creation. It can be used to perform some operation on hashing related algorithm like a hashta 1 min read Like