Path hashCode() method in Java with Examples
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 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); } } |
Hash Code: 1600751599
Program 2:
// 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); } } |
Hash Code: -996777206
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#hashCode()
Recommended Posts:
- Map hashCode() Method in Java with Examples
- Set hashCode() method in Java with Examples
- Float hashCode() method in Java with examples
- ZonedDateTime hashCode() method in Java with Examples
- ChronoZonedDateTime hashCode() method in Java with Examples
- UUID hashCode() Method in Java with Examples
- DecimalFormatSymbols hashCode() method in Java with Examples
- MonthDay hashCode() method in Java with Examples
- AbstractSet hashCode() Method in Java with Examples
- Date hashCode() method in Java with Examples
- Year hashCode() method in Java with Examples
- AbstractMap hashCode() Method in Java with Examples
- Properties hashCode() method in Java with Examples
- ChronoLocalDate hashCode() method in Java with Examples
- Level 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.


