Package hashCode() method in Java with Examples Last Updated : 14 Feb, 2022 Comments Improve Suggest changes Like Article Like Report 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 value as an integer value.Below programs demonstrate the hashCode() method.Example 1: Java // Java program to demonstrate // hashCode() method public class Test { public static void main(String[] args) { // returns the Package // object for this package Package myPackage = Package.getPackage("java.lang"); System.out.println( "Package represented by myPackage: " + myPackage.toString()); // get the hashCode value of this package // using hashCode() method System.out.println( "hashCode value: " + myPackage.hashCode()); } } Output: Package represented by myPackage: package java.lang, Java Platform API Specification, version 1.8 hashCode value: -888658374 Example 2: Java // Java program to demonstrate // hashCode() method public class Test { public static void main(String[] args) { // returns the Package // object for this package Package myPackage = Package.getPackage("java.io"); System.out.println( "Package represented by myPackage: " + myPackage.toString()); // get the hashCode value of this package // using hashCode() method System.out.println( "hashCode value: " + myPackage.hashCode()); } } Output: Package represented by myPackage: package java.io, Java Platform API Specification, version 1.8 hashCode value: -1819917198 Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Package.html#hashCode-- Comment More infoAdvertise with us Next Article Package hashCode() method in Java with Examples G guptayashgupta53 Follow Improve Article Tags : Java Java-lang package Java-Functions java.lang.Package Class Practice Tags : Java Similar Reads 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. 2 min read Stack hashCode() method in Java with Example The Java.util.Stack.hashCode() method in Java is used to get the hashcode value of this Stack. Syntax: Stack.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Stack which is of Integer type. Below programs illustrate the Java.util 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 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 Like