Java.lang Package Classes

Java Package - hashCode() Method



The java.lang.Package.hashCode() method returns the hash code computed from the package name.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns the hash code computed from the package name.

Exception

NA.

Example:

In the example below, the java.lang.Package.hashCode() method returns the hash code of the given package.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //create a java util package object
    Package p = Package.getPackage("java.util");

    //print the hashcode of this package
    System.out.println("The hashCode is: " + p.hashCode());
  }
}

The output of the above code will be:

The hashCode is: -888372146

❮ Java.lang - Package